|- Worker node
  |- Docker runtime (or containerd)
    |- Namespace
      |- POD
        |- Container(Application), Container(sidecar)

Kubernetes Architecture
Docker Commands
Docker vs Kubernets.

Command comparison (docker vs Kubernetes)

Same intent, different CLI. Kubernetes almost always needs a namespace (-n my-namespace). Docker has no equivalent unless you invent one with compose project names.

Build, Run, list, stop, delete

Concept / Action Docker Kubernetes
List All(Running, stopped) Items docker ps -a kubectl get pods -A (all namespaces)
Buid a image docker build -t myapp:1 . Note: Kubernetes does not build images, It only Pull images and create:
Pods, Deployments, or Services based on yaml
kubectl apply -f deloy.yaml

- if resource already exist, it will update with new values
Stop Container(docker), pod(kuberenetes) docker stop container_name kubectl delete pod pod_name
Remove Container(docker), pod(kuberenetes) docker rm container_name kubectl delete pod pod_name
Restart Container(docker), pod(kuberenetes) docker restart container_name kubectl rollout restart deploy pod_name
Rolling restart
Scale Container(docker), pod(kuberenetes) docker compose up --scale container_name=3 kubectl scale deploy pod_naame --replicas=3

Logs, shell, inspect, copy, stats

Action Docker Kubernetes
Logs docker logs container_name kubectl logs -f pod_name -c app
Shell inside docker exec -it container_name bash kubectl exec -it pod_name -c app -- sh
Inspect details docker inspect container_name kubectl get pod pod_name -o yaml
Copy files docker cp container_name:/app/log.txt . kubectl cp namespace/pod_name:/app/log.txt ./log.txt
CPU / memory docker stats kubectl top pod
kubectl top node

Ports, env, volumes

What you want Docker Kubernetes Note
Publish a port docker run -p 8080:80 nginx containerPort in the Pod spec, then a Service:
kubectl expose deploy web --port=80 --type=NodePort
-p binds this host. A Service is a stable cluster name/IP; Ingress / LoadBalancer is how users reach it. See Ports.
Env vars docker run -e KEY=val nginx env in Pod spec, or ConfigMap / Secret Do not put secrets in the image. Use Secret objects.
Mount a directory docker run -v /data:/data nginx volumeMounts + PersistentVolumeClaim Bind mounts are node-local. PVC can move with the Pod (depending on storage class). See PVC.

Kubernetes Commands

Namespace Commands

List Namespace


$ systemctl status kubectl       //if kubernets is installed
$ kubectl get namespaces
$ kubectl get pods -n my-namespace
        

Create namespace


$ kubectl create namespace my-namespace                                 // Create namespace
$ kubectl config  set-context --current --namespace=my-namespace        // Make namespace default
      

Delete namespace


$ kubectl delete namespace {namespace-name}
      

Pod Commands

Create POD inside namespace


$ kubectl apply -f deployment.yaml           // Namespace name provided inside yml file
      

List Pods, Containers in Pod


$ kubectl get pods -n namespace
$ kubectl get pods -A

//List all containers in pod
$ kubectl describe pod pod-name -n my-namespace
      

Delete Pods


$ kubectl delete pod pod-name                         // Deployment will recreate this Pod
$ kubectl delete deployment deploy-name
$ kubectl delete deployment deploy-name --grace-period=0 --force
          

Container Commands

These are Docker commands on a single host. They are not kubectl. Use them for local images / containers, or only on a node if you know Docker is the runtime and you are not touching kubelet-managed containers.

List Containers


$ docker ps
$ docker inspect 7d8b5d857e84
      

Remove Containers


$ docker rm container-id
      

Enter into Container


$ sudo docker exec -it <container-name> bash      // Go into container
$ sudo netstat -lpantu        //u=udp,t=tcp           //List process and ports