Knowledge

Creating and managing Pods

Updated 2026-11-08 · Present

Estimated time: 75 minutes.

Machines used in this guide

Machine Role Address
cp-1 Control plane 192.0.2.11
worker-1 Worker 192.0.2.12
worker-2 Worker 192.0.2.13

The addresses in this guide are illustrative addresses from the range reserved for documentation (RFC 5737); when you follow along, substitute your own machines' addresses.

Quick summary

Step 1 — Create a Deployment and read the Pod status with get / get -o wide

A Deployment describes the desired state (image, replica count) and generates a ReplicaSet to create Pods (Kubernetes: Deployment); each Pod gets an IP within the pod CIDR of the node the scheduler assigns. The NODE column and the IP octet tell you right away where the Pod sits without another command. This is the first observation step before going deeper into the container.

When it breaks: Running only kubectl get pods (without -o wide) hides the IP/NODE, so it is easy to skip matching the Pod to the right node when debugging cross-node traffic.

$ kubectl create deployment test-nginx --image=nginx
deployment.apps/test-nginx created

$ kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
test-nginx-5fd56bf67b-ntcjd   1/1     Running   0          2s

$ kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP           NODE
test-nginx-5fd56bf67b-ntcjd   1/1     Running   0          2s    10.244.2.5   worker-2

Observe with:

kubectl get pods -o wide and look at the IP/NODE columns

Note: The Pod got IP 10.244.2.5, which is within the 10.244.2.0/24 range that the controller-manager assigned to worker-2.

Step 2 — Run commands inside the container with exec, using the correct `--` syntax

The kubectl exec documentation requires separating kubectl's flags from the command to run in the container with -- (kubectl exec reference). Every token after -- is treated as the command and arguments sent into the container, not as kubectl flags; getting the syntax wrong is a typing error, not an image error.

When it breaks: Typing kubectl exec -it <pod> --bash reports the error unknown flag: --bash, which is easy to misread as the image lacking bash when the real cause is incorrect kubectl syntax.

$ kubectl exec test-nginx-5fd56bf67b-ntcjd -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=test-nginx-5fd56bf67b-ntcjd
NGINX_VERSION=1.31.6
NJS_VERSION=1.0.1
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
HOME=/root

$ kubectl exec test-nginx-5fd56bf67b-ntcjd -- hostname
test-nginx-5fd56bf67b-ntcjd

Observe with:

kubectl exec <pod> -- env; kubectl exec <pod> -- hostname

Symptoms when it breaks:

How to fix:

  1. Add a space between the two dashes and the command name

    kubectl exec -it test-nginx-5fd56bf67b-ntcjd -- bash
    

Note: The hostname inside the container is the Pod name, not the node name; a log line that records the hostname therefore identifies the Pod only and does not tell you which node the Pod runs on.

Step 3 — Read the cause through describe, not get

The Events chain in kubectl describe pod records the handoffs between the scheduler and the kubelet over time (Scheduled → Pulling → Pulled → Created → Started); the Container ID field confirms that the runtime really created the container. kubectl get gives only the instantaneous state and does not tell you which steps the Pod went through to get there.

When it breaks: Looking only at STATUS Running from get pods skips the image pull time and the node name the scheduler chose, which you need when comparing performance between Pod creations or confirming which runtime is in use.

$ kubectl describe pod test-nginx-5fd56bf67b-ntcjd
Containers:
  nginx:
    Container ID:   containerd://744e88fe2316e55714b712b10ff2b9e26196ed35956a1461cb3b463fd5a0f12b
    Image:          nginx
    State:          Running
    Ready:          True
    Restart Count:  0
Events:
  Type    Reason     Age   From               Message
  Normal  Scheduled  2s    default-scheduler  Successfully assigned default/test-nginx-5fd56bf67b-ntcjd to worker-2
  Normal  Pulling    2s    kubelet            Pulling image "nginx"
  Normal  Pulled     1s    kubelet            Successfully pulled image "nginx" in 361ms. Image size: 66343686 bytes.
  Normal  Created    1s    kubelet            Created container: nginx
  Normal  Started    1s    kubelet            Started container nginx

Observe with:

kubectl describe pod <pod> and read the Containers and Events sections

Note: A Container ID of the form containerd://... confirms that the runtime is containerd, not Docker; the image pull took 361ms thanks to the mirror.gcr.io declared in the cluster-building step.

Step 4 — Scale a Deployment and read the right ReplicaSet, not 'scale the container'

A ReplicaSet keeps exactly spec.replicas Pods; DESIRED/CURRENT/READY are three different numbers: desired, created, and ready to receive traffic (Kubernetes: ReplicaSet). If it were "3 containers in 1 Pod", the READY column would read 3/3 with only one Pod line; what was measured is the complete opposite.

When it breaks: Calling --replicas=3 'adding containers to a Pod' leads to the wrong expectation when reading kubectl get pods: you see 3 separate Pod lines instead of 1 line with several containers.

$ kubectl scale deployment test-nginx --replicas=3
deployment.apps/test-nginx scaled

$ kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP           NODE
test-nginx-5fd56bf67b-jcs99   1/1     Running   0          3s    10.244.1.4   worker-1
test-nginx-5fd56bf67b-ntcjd   1/1     Running   0          5s    10.244.2.5   worker-2
test-nginx-5fd56bf67b-wp2nt   1/1     Running   0          3s    10.244.1.5   worker-1

$ kubectl get replicasets
NAME                    DESIRED   CURRENT   READY   AGE
test-nginx-5fd56bf67b   3         3         3       5s

Observe with:

kubectl get pods -o wide; kubectl get replicasets

Note: Three Pods sharing the prefix test-nginx-5fd56bf67b = the same ReplicaSet. The READY column is still 1/1 for each Pod, which is the proof that these are 3 Pods, not 1 Pod with 3 containers.

Step 5 — Expose a NodePort and read the Endpoints: real Pod IPs, not the Deployment name

A Service selects Pods through a label selector; kubectl get endpoints records exactly the IP:port of the Pods that currently match, independent of the Deployment name (Kubernetes: Service). Empty endpoints are the first sign when a Service is "unreachable": a selector that matches no Pod label is the cause to rule out first.

When it breaks: Reading kubectl get services without reading the endpoints misses the most important sign when a Service cannot route traffic: the Service still shows a CLUSTER-IP even though no Pod stands behind it.

$ kubectl expose deployment test-nginx --type="NodePort" --port 80
service/test-nginx exposed

$ kubectl get services
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        3m23s
test-nginx   NodePort    10.107.187.174   <none>        80:31846/TCP   0s

$ kubectl get endpoints test-nginx
NAME         ENDPOINTS                                   AGE
test-nginx   10.244.1.4:80,10.244.1.5:80,10.244.2.5:80   0s

$ curl -o /dev/null -w "%{http_code}" http://192.0.2.11:31846/   ->  200
$ curl -o /dev/null -w "%{http_code}" http://192.0.2.12:31846/   ->  200
$ curl -o /dev/null -w "%{http_code}" http://192.0.2.13:31846/   ->  200

Observe with:

kubectl get services; kubectl get endpoints <svc>

Note: Port 31846 is open on all 3 nodes, including cp-1, which runs no Pod of the service: kube-proxy on every node has a DNAT rule to the Pod IP. The port falls within the default range 30000–32767.

Step 6 — Delete a Pod and watch the ReplicaSet build a new one

A ReplicaSet tracks the actual Pod count through a watch and, when it sees a mismatch with spec.replicas, creates a new Pod right away (Kubernetes: ReplicaSet). A deleted Pod does not come back; the new Pod has a different name, a different IP, and may be on a different node. The disposable thing is the Pod; the durable things are the Deployment and the Service.

When it breaks: Expecting a Pod to be 'resurrected' with the same name/IP after deletion leads to hardcoding the Pod IP in other configuration; a new Pod always has a completely new identity.

14:57:16 $ kubectl delete pod test-nginx-5fd56bf67b-jcs99
pod "test-nginx-5fd56bf67b-jcs99" deleted

14:57:24 $ kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP           NODE
test-nginx-5fd56bf67b-mcggb   1/1     Running   0          8s    10.244.2.6   worker-2
test-nginx-5fd56bf67b-ntcjd   1/1     Running   0          13s   10.244.2.5   worker-2
test-nginx-5fd56bf67b-wp2nt   1/1     Running   0          11s   10.244.1.5   worker-1

Observe with:

kubectl get pods -o wide before and after the deletion

Note: The new Pod appeared 8 seconds after the deletion, with a different name and a different IP, and the ReplicaSet chose node worker-2 instead of the old worker-1.

Step 7 — Diagnose ImagePullBackOff: the Pod is already Scheduled, then fails to pull the image

The kubelet progressively lengthens the retry interval for pulling an image using an exponential backoff mechanism when the image cannot be pulled (Kubernetes: ImagePullBackOff). A successful Scheduled event is the evidence that distinguishes this failure from Pending: the Pod already has a node and simply has not been able to pull the image.

When it breaks: Concluding 'the registry network is down' from the error alone without reading its content carefully. The specific message on the lab cluster is characteristic of going through a mirror, not a generic connection error.

$ kubectl run badimage --image=nginx:khong-co-tag-nay --restart=Never
$ kubectl get pod badimage
NAME       READY   STATUS             RESTARTS   AGE
badimage   0/1     ImagePullBackOff   0          25s

$ kubectl describe pod badimage
Events:
  Normal   Scheduled  25s               default-scheduler  Successfully assigned default/badimage to worker-1
  Normal   Pulling    5s (x2 over 25s)  kubelet            Pulling image "nginx:khong-co-tag-nay"
  Warning  Failed     2s (x2 over 17s)  kubelet            Failed to pull image "nginx:khong-co-tag-nay": rpc error: code = NotFound desc = get image config descriptor: unexpected media type text/html for sha256:43aeb746...: not found
  Warning  Failed     2s (x2 over 17s)  kubelet            Error: ErrImagePull
  Normal   BackOff    16s               kubelet            Back-off pulling image "nginx:khong-co-tag-nay"
  Warning  Failed     16s               kubelet            Error: ImagePullBackOff

Observe with:

kubectl get pod badimage; kubectl describe pod badimage

Symptoms when it breaks:

How to fix:

  1. Confirm the tag exists on the registry before recreating the Pod with the correct tag

    kubectl delete pod badimage && kubectl run badimage --image=nginx:1.27 --restart=Never
    

Note: The error message is 'unexpected media type text/html' rather than 'manifest unknown' as with Docker Hub directly, because the cluster goes through mirror.gcr.io, and the mirror returns an HTML page when the image does not exist.

Step 8 — Reproduce CrashLoopBackOff properly: you need a restartPolicy other than Never

restartPolicy decides whether the kubelet tries to restart a Terminated container (Kubernetes: restart policy). RESTARTS is a more reliable number than STATUS for judging severity, because STATUS flips back and forth between two values while RESTARTS only increases.

When it breaks: Treating RESTARTS=0 STATUS=Error as 'milder' than CrashLoopBackOff. It is really a difference in restartPolicy (Never versus Always/OnFailure), not two severity levels of the same failure.

$ kubectl run crasher --image=busybox:1.36 --restart=Never --command -- sh -c 'echo "khoi dong roi chet"; exit 1'
$ kubectl get pod crasher
NAME      READY   STATUS   RESTARTS   AGE
crasher   0/1     Error    0          45s

$ kubectl logs crasher
khoi dong roi chet

$ kubectl create deployment crashloop --image=busybox:1.36 -- sh -c 'echo "khoi dong roi chet"; exit 1'

t+ 20s  crashloop-59b4db4cd-hsfd5 READY=0/1 STATUS=Error             RESTARTS=2
t+ 40s  crashloop-59b4db4cd-hsfd5 READY=0/1 STATUS=CrashLoopBackOff  RESTARTS=2
t+ 60s  crashloop-59b4db4cd-hsfd5 READY=0/1 STATUS=CrashLoopBackOff  RESTARTS=3
t+ 80s  crashloop-59b4db4cd-hsfd5 READY=0/1 STATUS=CrashLoopBackOff  RESTARTS=3
t+100s  crashloop-59b4db4cd-hsfd5 READY=0/1 STATUS=Error             RESTARTS=4

$ kubectl describe pod crashloop-59b4db4cd-hsfd5
    State:          Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Thu, 17 Sep 2026 15:01:40 +0700
      Finished:     Thu, 17 Sep 2026 15:01:40 +0700
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Thu, 17 Sep 2026 15:00:48 +0700
      Finished:     Thu, 17 Sep 2026 15:00:48 +0700

$ kubectl logs crashloop-59b4db4cd-hsfd5 --previous
unable to retrieve container logs for containerd://7062197422db...

Observe with:

kubectl get pod to watch RESTARTS; kubectl describe pod to read State/Last State

Symptoms when it breaks:

How to fix:

  1. Capture the log right after you notice RESTARTS increasing, or collect logs into a centralized logging system instead of relying only on --previous

    kubectl logs <pod> --previous
    

Note: State and Last State both show Exit Code: 1 with the same Started/Finished second, a sign of an error in the application (it exits immediately on startup), not an infrastructure error.

Step 9 — Diagnose Pending: logs are meaningless, you must describe

Pending means the Pod has been accepted but no container has been created yet (Kubernetes: pod phase); a single FailedScheduling Event line tells you everything about the cluster configuration at that moment: how many nodes were ruled out and the specific reason for each node.

When it breaks: Running kubectl logs toobig while the Pod is Pending returns an error or nothing, which is easy to misread as lost logs when in fact no container was ever created to produce logs.

$ kubectl run toobig --image=nginx --restart=Never --overrides='{"spec":{"containers":[{"name":"toobig","image":"nginx","resources":{"requests":{"memory":"64Gi"}}}]}}'
$ kubectl get pod toobig
NAME     READY   STATUS    RESTARTS   AGE
toobig   0/1     Pending   0          12s

$ kubectl describe pod toobig
Events:
  Warning  FailedScheduling  12s  default-scheduler  0/3 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 2 Insufficient memory. preemption: 0/3 nodes are available: 1 Preemption is not helpful for scheduling, 2 No preemption victims found for incoming pod.

Observe with:

kubectl get pod toobig; kubectl describe pod toobig and read Events

Symptoms when it breaks:

How to fix:

  1. Lower requests.memory below the node's allocatable RAM before recreating it

    kubectl get node -o custom-columns=NAME:.metadata.name,MEM:.status.allocatable.memory
    

Step 10 — The control plane taint is enforced by the scheduler: nodeName bypasses it

kube-scheduler considers taints and tolerations when choosing a node for a new Pod; declaring .spec.nodeName directly skips that step (Kubernetes: taints and tolerations). A static Pod goes further: the kubelet reads the manifest straight from the node, without going through the apiserver or the scheduler (Kubernetes: static pods). This is why etcd and kube-apiserver can run on a tainted control plane node.

When it breaks: Believing that setting a taint is enough to fully isolate a node from every workload. That is only true for workloads that go through the normal scheduler, not for a Pod that declares nodeName or for a static pod.

$ kubectl create deployment spread --image=nginx --replicas=6
$ kubectl get pod -l app=spread -o custom-columns='NODE:.spec.nodeName' --no-headers | sort | uniq -c
      3 worker-1
      3 worker-2

$ kubectl get node cp-1 -o jsonpath='{.spec.taints}'
[{"effect":"NoSchedule","key":"node-role.kubernetes.io/control-plane"}]

$ kubectl run pinned --image=nginx --restart=Never --overrides='{"spec":{"nodeName":"cp-1"}}'
pinned   1/1   Running   0   13s   10.244.0.5   cp-1

Observe with:

kubectl get pod -l app=spread -o custom-columns=NODE:.spec.nodeName; kubectl get node <cp> -o jsonpath="{.spec.taints}"

Note: NoSchedule is a scheduler rule, not a kubelet gate. If you bypass the scheduler, the taint has no effect.

Step 11 — Measure enough samples before concluding anything about NodePort distribution

kube-proxy in iptables mode picks the destination endpoint at random per connection, not in even round-robin (Kubernetes: proxy-mode iptables); the default externalTrafficPolicy: Cluster lets a request arriving at one node be forwarded to a Pod on another node (Kubernetes: traffic policies). 3 samples are far too few to conclude anything about the distribution mechanism.

When it breaks: Concluding that 'a NodePort always sticks to one Pod' from 3 coincidental curl calls sends the investigation in the wrong direction when it is really randomness on a small sample.

$ curl http://192.0.2.11:30001/
Hello, world! Version: 1.0.0 Hostname: hello-app-7d9f89775b-zphz2
$ curl http://192.0.2.12:30001/
Hello, world! Version: 1.0.0 Hostname: hello-app-7d9f89775b-zphz2
$ curl http://192.0.2.13:30001/
Hello, world! Version: 1.0.0 Hostname: hello-app-7d9f89775b-zphz2

# 30 requests to the NodePort of ONE node
     11 hello-app-7d9f89775b-m9dr7
     19 hello-app-7d9f89775b-zphz2

# 30 requests, alternating across all 3 nodes
     14 hello-app-7d9f89775b-m9dr7
     16 hello-app-7d9f89775b-zphz2

Observe with:

Repeat curl N≥30 times and count by the hostname returned in the response

Note: The first three curl calls hitting the same Pod zphz2 was just a coincidence of a small sample; only 30 requests revealed the nearly even 11/19 and 14/16 splits between the two Pods.

Common misconceptions

A ReplicaSet keeps exactly spec.replicas Pods by creating or deleting Pods that match the label selector, not by changing the number of containers in the pod template (Kubernetes: ReplicaSet, Kubernetes: Deployment). Measured on the lab cluster on 2026-09-17: kubectl scale deployment test-nginx --replicas=3 created three Pods -jcs99, -ntcjd, -wp2nt, each with READY 1/1; kubectl get replicasets returned DESIRED 3 CURRENT 3 READY 3. If it really were "3 containers in 1 Pod", it would read 3/3 and there would be only a single Pod line. Consequence for counting resources: the unit to count when making a capacity plan is the number of lines returned by kubectl get pods, not the value passed to --replicas; confusing the two concepts leads to a wrong estimate of how many real Pods are consuming CPU/RAM on a node.

The kubectl exec documentation requires using -- to separate kubectl's flags from the command run in the container when that command could collide with kubectl's own flags (kubectl exec reference). Measured on the lab cluster on 2026-09-17: kubectl exec test-nginx-5fd56bf67b-ntcjd -- env and -- hostname ran successfully and returned the Pod's actual environment variables and hostname. Writing --bash joined without a space makes kubectl parse it as a flag of kubectl itself and report unknown flag, never having touched the container. Consequence when reading the error: unknown flag: --bash is a kubectl syntax error, not a sign that the image lacks a shell or that the container is not ready; fix it by adding a space, not by changing the image.

A Pod's restartPolicy decides whether the kubelet restarts a container that has Terminated (Kubernetes: restart policy). Measured on the lab cluster on 2026-09-17: the Pod crasher, created with kubectl run --restart=Never, stayed at STATUS Error with RESTARTS 0 throughout the 45 seconds of observation. The Pod crashloop-59b4db4cd-hsfd5, created through a Deployment (default restartPolicy Always), oscillated between Error and CrashLoopBackOff from t+20s to t+100s while RESTARTS rose 2 → 3 → 4. Consequence when reading incident logs: reading STATUS once easily leads to a wrong conclusion because it oscillates; RESTARTS is the more trustworthy number for judging severity, and to reproduce a genuine CrashLoopBackOff you must create the Pod through a Deployment/ReplicaSet and not with --restart=Never.

Pending is the phase in which the Pod has been accepted by the apiserver but no container has been created yet, either because no node has been assigned or because a node was assigned but the image is still being pulled (Kubernetes: pod phase). Measured on the lab cluster on 2026-09-17: the Pod toobig, asking for requests.memory: 64Gi, stayed in STATUS Pending; kubectl describe pod toobig gave the event FailedScheduling ... 2 Insufficient memory. No container was ever created, so there was no log to read. Consequence when diagnosing: when you see STATUS Pending, skip kubectl logs and read the Events section of kubectl describe pod directly; it is the only place that records the reason the Pod has not been assigned to a node.

kube-scheduler considers taints and tolerations when choosing a node for a Pod; declaring .spec.nodeName directly on a Pod skips that step (Kubernetes: taints and tolerations). A static Pod goes further: the kubelet reads the manifest straight from the configuration directory on the node, without going through the apiserver or the scheduler (Kubernetes: static pods). Measured on the lab cluster on 2026-09-17: the spread Deployment with 6 replicas put no Pod on cp-1 (the node carrying the taint node-role.kubernetes.io/control-plane:NoSchedule); the Pod pinned, which declares nodeName: cp-1 directly, ran Running 1/1 right on that node. Consequence: this is why system static Pods (etcd, kube-apiserver) can run on a tainted control plane node, since they do not go through the scheduler and so the taint does not apply; the conclusion that "taint = absolute isolation" is wrong for both of these Pod types.

Hands-on 1 — Create, observe, and get inside a Pod on a real cluster

20 minutes

Rebuild the official documentation's basic sequence of commands on the control plane node cp-1, fixing the --bash syntax error as soon as you hit it (kubectl exec reference).

kubectl create deployment test-nginx --image=nginx ; kubectl get pods -o wide ; kubectl exec <pod> -- env ; kubectl describe pod <pod>

Observation: The IP/NODE columns of get -o wide; the Events section of describe pod

1. SSH into the control plane cp-1, run kubectl create deployment test-nginx --image=nginx, then kubectl get pods -o wide.

The Deployment is created successfully; 1 Pod Running 1/1, with an IP of the form 10.244.x.x within the range of the node it runs on.

2. Run kubectl exec <pod> -- env and then kubectl exec <pod> -- hostname.

You see the variable KUBERNETES_SERVICE_HOST=10.96.0.1; the hostname returns the Pod name, not the node name.

3. Try exactly what the original documentation says: kubectl exec -it <pod> --bash.

It reports the error unknown flag: --bash. Fix it to kubectl exec -it <pod> -- bash to get into the shell.

4. Run kubectl describe pod <pod> and read the Events section.

The chain Scheduled → Pulling → Pulled → Created → Started; the Container ID is of the form containerd://...

Analysis

Observation: The whole create/observe/interact sequence on a Pod works exactly as the documentation says, apart from one exec syntax error that needs fixing.

Mechanism: get reads the instantaneous state; describe reads Events over time; exec sends the command into the container through the API server and then the kubelet, and needs the correct -- syntax to separate the flags.

Takeaway: get/describe/exec answer three different questions; an exec syntax error is a typing error, not an image or container error.

Troubleshooting:

Hands-on 2 — Scale, expose a NodePort, and read the Endpoints

20 minutes

See directly that the ReplicaSet is the unit that counts Pods (not "scaling the container"), and that a Service selects Pods through Endpoints and not through the Deployment name (Kubernetes: ReplicaSet, Kubernetes: Service).

kubectl scale deployment test-nginx --replicas=3 ; kubectl expose deployment test-nginx --type=NodePort --port 80 ; kubectl get endpoints test-nginx

Observation: kubectl get replicasets; kubectl get endpoints test-nginx

1. On the control plane: kubectl scale deployment test-nginx --replicas=3, then kubectl get pods -o wide and kubectl get replicasets.

3 separate Pods Running 1/1, each with a different IP; ReplicaSet DESIRED 3 CURRENT 3 READY 3.

2. Expose: kubectl expose deployment test-nginx --type="NodePort" --port 80, then kubectl get services.

A NodePort Service with PORT of the form 80:3xxxx/TCP; the specific port is allocated by the cluster in the range 30000–32767.

3. Read kubectl get endpoints test-nginx.

Exactly 3 IP:80 addresses matching the 3 Running Pods; no Deployment name appears in the output.

4. Curl the NodePort from all 3 node addresses: curl -o /dev/null -w "%{http_code}" http://192.0.2.1X:<nodeport>/ with X = 1, 2, 3 (cp-1, worker-1, worker-2) and <nodeport> the port after the colon in step 2.

All 3 return HTTP 200, even the node that runs no Pod of this service.

Analysis

Observation: The ReplicaSet and the Endpoints are the two places that give the true numbers; the Service/NodePort works independently of which node a Pod is on.

Mechanism: The ReplicaSet uses a label selector to count Pods; kube-proxy sets up DNAT rules on every node for every NodePort Service.

Takeaway: When a Service is "unreachable", read the endpoints before suspecting the network; when you need to know the real Pod count, read the replicasets instead of guessing from the --replicas parameter.

Troubleshooting:

Hands-on 3 — Self-healing and cleanup

10 minutes

Watch directly as the ReplicaSet creates a replacement Pod after a deletion, and confirm that a Service must be deleted separately because it is not part of the ownership chain Deployment → ReplicaSet → Pod (Kubernetes: ReplicaSet).

kubectl delete pod <ten-pod> ; kubectl get pods -o wide ; kubectl delete services test-nginx ; kubectl delete deployment test-nginx

Observation: kubectl get pods -o wide before and right after deleting the Pod; kubectl get all after deleting the Service/Deployment

1. Note the current list of Pods (kubectl get pods -o wide), then delete one Pod: kubectl delete pod <name>.

The deleted Pod disappears right away from kubectl get pods.

2. Wait about 10 seconds and run kubectl get pods -o wide again.

A new Pod appears with a different name and IP; on the lab cluster, 8 seconds were measured from the deletion until the new Pod could be read at STATUS Running.

3. Clean up: kubectl delete services test-nginx and then kubectl delete deployment test-nginx, followed by kubectl get all.

The Service is deleted separately; deleting the Deployment takes the ReplicaSet and all the Pods with it. kubectl get all shows only service/kubernetes left.

Analysis

Observation: The ReplicaSet reacts almost instantly when the Pod count drops; the Service does not disappear while the Deployment still exists, and vice versa.

Mechanism: The ReplicaSet controller runs a continuous watch loop and does not wait for any command to trigger it again; a Service is an independent object with no OwnerReference to the Deployment.

Takeaway: A Pod is a disposable resource; do not design an application that depends on keeping a Pod's name or IP over time.

Troubleshooting:

Hands-on 4 — Diagnose 4 Pod failures (ImagePullBackOff, Error/CrashLoopBackOff, Pending, taint)

25 minutes

Reproduce the four Pod failures with four different diagnostic approaches. Each failure requires reading exactly one data field in describe/get -o jsonpath, not the same action every time (ImagePullBackOff, restart policy, pod phase, taints and tolerations).

kubectl run badimage --image=nginx:khong-co-tag-nay --restart=Never ; kubectl run crasher --image=busybox:1.36 --restart=Never --command -- sh -c 'exit 1' ; kubectl create deployment crashloop --image=busybox:1.36 -- sh -c 'exit 1' ; kubectl run toobig --overrides='{"spec":{"containers":[{"name":"toobig","image":"nginx","resources":{"requests":{"memory":"64Gi"}}}]}}' --image=nginx --restart=Never

Observation: kubectl describe pod for each case; kubectl get pod -o jsonpath for taint/nodeName

1. Create kubectl run badimage --image=nginx:khong-co-tag-nay --restart=Never and then kubectl describe pod badimage.

STATUS ImagePullBackOff; Events show a successful Scheduled before Pulling/Failed: the Pod already has a node and simply has not been able to pull the image.

2. Create kubectl run crasher --image=busybox:1.36 --restart=Never --command -- sh -c 'echo "khoi dong roi chet"; exit 1' and then kubectl create deployment crashloop --image=busybox:1.36 -- sh -c 'echo "khoi dong roi chet"; exit 1'.

crasher stays at STATUS Error with RESTARTS 0 forever; crashloop oscillates between Error and CrashLoopBackOff, with RESTARTS rising across kubectl get pod calls about 20 seconds apart.

3. Create a Pod that asks for more RAM than the nodes can offer: kubectl run toobig --image=nginx --restart=Never --overrides='{"spec":{"containers":[{"name":"toobig","image":"nginx","resources":{"requests":{"memory":"64Gi"}}}]}}' and then kubectl describe pod toobig.

STATUS Pending; the FailedScheduling event clearly lists 1 node ruled out because of the taint and 2 nodes ruled out because of Insufficient memory.

4. Create kubectl create deployment spread --image=nginx --replicas=6, count the nodes with kubectl get pod -l app=spread -o custom-columns=NODE:.spec.nodeName --no-headers | sort | uniq -c; then kubectl run pinned --image=nginx --restart=Never --overrides='{"spec":{"nodeName":"cp-1"}}'.

No replica of spread lands on cp-1 (the tainted control plane node); pinned runs Running 1/1 right on that node.

5. Clean everything up: kubectl delete pod badimage crasher toobig pinned; kubectl delete deployment crashloop spread.

All the test Pods and Deployments disappear from kubectl get all.

Analysis

Observation: The four failures have four different signs in Events and container state, and none can be diagnosed with the same command.

Mechanism: ImagePullBackOff and Pending both happen before any container exists, but differ in whether the Pod was already Scheduled; Error/CrashLoopBackOff happen after a container exists, and differ in whether restartPolicy allows a retry (Never does not, Always/OnFailure do); a taint blocks only Pods that go through the normal scheduler.

Takeaway: A Pod diagnosis runbook should branch first on the observable STATUS and only then choose the right data field to read, rather than applying the same action to every failure.

Troubleshooting:

Review questions

Question 1. On the lab cluster, after kubectl scale deployment test-nginx --replicas=3, what READY value was measured for each Pod, and what does it prove?

  1. 3/3, which proves each Pod now has 3 containers
  2. 1/1 on all three Pods, which proves --replicas creates additional Pods and does not add containers to the old Pod
  3. 0/1, the Pod is not ready right after the scale
  4. 1/3, one of the three Pods is not Ready

Answer: 1/1 on all three Pods, which proves --replicas creates additional Pods and does not add containers to the old Pod. Measured on 2026-09-17: kubectl get pods -o wide after the scale shows 3 Pods, each with READY 1/1; kubectl get replicasets shows DESIRED 3 CURRENT 3 READY 3, three numbers about Pods and not about containers. The other options: READY 3/3 would only happen if 3 containers were in 1 Pod, which is not what --replicas does; the remaining two options do not match the measured figures, since all 3 Pods were Running 1/1 at AGE 3-5s.

Question 2. What is the correct syntax to open a bash shell inside a Pod with kubectl exec?

  1. kubectl exec -it <pod> --bash
  2. kubectl exec -it <pod> -- bash
  3. kubectl exec <pod> --shell bash
  4. kubectl bash <pod>

Answer: kubectl exec -it <pod> -- bash. kubectl exec needs -- to separate kubectl's flags from the command run in the container (kubectl exec reference). The other options: --bash joined without a space is read by kubectl as a flag of its own and so reports unknown flag; the remaining two options are not valid kubectl exec syntax.

Question 3. The Pod crasher (kubectl run --restart=Never) and the Pod crashloop (created through a Deployment) both run a script that exits 1. What difference in STATUS was observed?

  1. Both are CrashLoopBackOff because of the same application error
  2. crasher stays at Error with RESTARTS=0 forever; crashloop oscillates between Error and CrashLoopBackOff with RESTARTS rising
  3. crasher recovers on its own after a few seconds
  4. crashloop never shows STATUS Error

Answer: crasher stays at Error with RESTARTS=0 forever; crashloop oscillates between Error and CrashLoopBackOff with RESTARTS rising. crasher's restartPolicy: Never means that once the container dies, that is the end; Always (the Deployment default) and OnFailure both make the kubelet retry with backoff, producing a chain of Error/CrashLoopBackOff with RESTARTS rising, measured as 2→3→4 on crashloop-59b4db4cd-hsfd5 (Always) and RESTARTS=3 with CrashLoopBackOff at t+66s on the Pod onfail (OnFailure). The other options: crasher does not recover on its own, it stops for good at Error; crashloop shows both STATUS values alternating over time, not only CrashLoopBackOff.

Question 4. In describe, which event differs between the Pod badimage (nonexistent image tag) and the Pod toobig (Pending because of insufficient RAM)?

  1. badimage has no Scheduled event, toobig does
  2. badimage has a successful Scheduled event and then fails to pull the image; toobig never had a successful Scheduled event
  3. Neither has any event
  4. toobig has a Container ID and badimage does not

Answer: badimage has a successful Scheduled event and then fails to pull the image; toobig never had a successful Scheduled event. Evidence: badimage has the Events Scheduled ... Successfully assigned ... to worker-1 before Pulling/Failed; toobig has only FailedScheduling and was never assigned a node. The other options: The option saying toobig is the Pod that got Scheduled is exactly backwards: it is badimage that has the Scheduled event; the option saying neither has any event is also wrong, since both have Events, just of different kinds; and toobig has no Container ID because no container was ever created.

Question 5. Why does kubectl logs toobig have no diagnostic value?

  1. Because the logs were cleaned up by the runtime
  2. Because the Pod is Pending, so no container has been created to produce logs
  3. Because toobig runs on the tainted control plane node
  4. Because logs can only be read for a Deployment, not for a bare Pod

Answer: Because the Pod is Pending, so no container has been created to produce logs. Pending is the phase in which the Pod has no container created yet (Kubernetes: pod phase); with no container there is nothing for logs to read. The other options: Logs being cleaned up is a different phenomenon (the evidence from crashloop, not toobig); toobig was never assigned a node, so the taint is irrelevant; logs can be read for a bare Pod as well as a Pod created by a Deployment, as long as a container exists.

Question 6. The spread Deployment with 6 replicas has no Pod on the control plane node tainted NoSchedule. The Pod pinned, which declares nodeName: cp-1, runs Running on that very node. Why?

  1. The NoSchedule taint is only considered by kube-scheduler when choosing a node; declaring nodeName directly bypasses the scheduler
  2. The taint applies only to Deployments, not to bare Pods
  3. pinned has a hidden default toleration
  4. The control plane node had its taint removed before pinned was created

Answer: The NoSchedule taint is only considered by kube-scheduler when choosing a node; declaring nodeName directly bypasses the scheduler. kube-scheduler considers taints and tolerations when choosing a node for a new Pod; setting .spec.nodeName directly skips that node selection step (Kubernetes: taints and tolerations). The other options: The taint applies to every Pod that goes through the scheduler, whether it comes from a Deployment or is a bare Pod; pinned declares no toleration; the evidence records no removal of the taint before pinned was created.

Question 7. Why can a static Pod (etcd, kube-apiserver...) run on a tainted control plane node?

  1. The kubelet reads the manifest straight from the configuration directory on the node, without going through the scheduler, so the taint does not block it
  2. A static Pod always has a default toleration for every taint
  3. Taints apply only after the cluster has been running for a certain amount of time
  4. kube-scheduler prioritizes static Pods over ordinary Pods

Answer: The kubelet reads the manifest straight from the configuration directory on the node, without going through the scheduler, so the taint does not block it. The kubelet manages a static Pod directly from the manifest on the node, without going through the apiserver or the scheduler (Kubernetes: static pods). The other options: The documentation describes no default toleration mechanism for static Pods; a taint has no "expiry time"; the scheduler takes no part in building a static Pod, so there is no concept of priority.

Question 8. What are the Endpoints of the Service test-nginx after expose, and what do they prove about how a Service selects Pods?

  1. The Deployment name test-nginx, since the Service follows the Deployment name
  2. 3 IP:port addresses of exactly the 3 Running Pods, so the Service selects Pods through a label selector and not through the Deployment name
  3. Empty until the Deployment finishes scaling
  4. The node IPs, not the Pod IPs

Answer: 3 IP:port addresses of exactly the 3 Running Pods, so the Service selects Pods through a label selector and not through the Deployment name. kubectl get endpoints test-nginx returns exactly 10.244.1.4:80,10.244.1.5:80,10.244.2.5:80, three real Pod IPs matching the Service's label selector (Kubernetes: Service). The other options: The Service object does not reference the Deployment name; endpoints appear when a Pod becomes Ready, not as soon as it is Running. Here nginx declares no readinessProbe, so Ready is almost simultaneous with Running, whereas a workload with a readinessProbe that is Running but not yet Ready will have no endpoint yet; the values in Endpoints are Pod IPs, not node IPs.

Question 9. Measuring the NodePort of hello-app with 30 repeated requests gave 11/19 and then 14/16 between the two Pods. Which conclusion is correct according to these figures?

  1. kube-proxy splits perfectly evenly at 15/15 every time
  2. The first three curl calls hitting the same Pod prove that a NodePort always sticks to one Pod
  3. The iptables proxy picks an endpoint at random per connection; a skew of 11/19 or 14/16 is still normal behavior for a small sample
  4. This result cannot be measured a second time

Answer: The iptables proxy picks an endpoint at random per connection; a skew of 11/19 or 14/16 is still normal behavior for a small sample. kube-proxy in iptables mode uses a statistic mode random rule, choosing randomly per connection rather than in perfectly balanced round-robin (Kubernetes: proxy-mode iptables). The other options: No mechanism guarantees a perfectly even split; 3 curl calls are far too small a sample to conclude anything about the mechanism; the measurement is repeatable and gave similar results (11/19 and then 14/16) across two different runs.

Flashcards