Knowledge
Creating and managing Pods
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
-
get / describe / logs: three different questions
- Why:
kubectl get podreads the summary status (STATUS/RESTARTS/AGE);kubectl describe podadditionally reads Events, the chain of scheduler and kubelet actions over time;kubectl logsreads the stdout/stderr of a container that has existed (Kubernetes: pod phase). The three commands answer three different questions and cannot replace one another. Measured on the lab cluster on 2026-09-17: describe of a normally running Pod shows the Events chain Scheduled → Pulling → Pulled → Created → Started; describe of a Pending Pod (toobig) shows only FailedScheduling, and there is no container at all for logs to read. Consequence: picking the wrong tool (running logs on a Pending Pod) returns a meaningless error. A practical rule: when STATUS is abnormal, describe first; logs is only useful once the container has started at least once. - When it breaks: Running
kubectl logson a Pending Pod returns an error or nothing, which is easy to misread as a broken cluster when the real cause is that no container has been created yet. - In real deployments: A Pod incident runbook should fix the order:
get -o wide→describe(read Events) →logs(only if the container has ever started). Avoid jumping straight to logs when STATUS is not yet Running/CrashLoopBackOff.
- Why:
-
Pod IPs follow the CIDR of the node they run on
- Why: The CNI assigns each Pod scheduled on a node an IP within that node's own pod CIDR. Measured on the lab cluster on 2026-09-17: the Pod
test-nginx-5fd56bf67b-ntcjdgot IP10.244.2.5, which lies in10.244.2.0/24, exactly the range the controller-manager assigned to nodeworker-2(recorded in the cluster-building step, Phase 2). Consequence: reading the third octet of a Pod IP tells you right away which node the Pod runs on without running-o wide, which helps when debugging cross-node pod-to-pod traffic. - When it breaks: Assuming a Pod IP stays fixed across recreations and hardcoding it into another application's configuration. A Pod that is deleted and recreated always gets a new IP, possibly on a completely different node.
- In real deployments: Do not hardcode a Pod IP in the configuration of an application that calls it; always call through the Service name. The Service/Endpoints mechanism is covered in the item below.
- Why: The CNI assigns each Pod scheduled on a node an IP within that node's own pod CIDR. Measured on the lab cluster on 2026-09-17: the Pod
-
A ReplicaSet is the unit that really counts Pods; a Deployment does not count them itself
- Why: A ReplicaSet identifies the Pods that belong to it through a label selector and keeps exactly
spec.replicasPods (Kubernetes: ReplicaSet). A Deployment owns ReplicaSets and does not directly own Pods. Measured on the lab cluster on 2026-09-17: afterkubectl scale deployment test-nginx --replicas=3,kubectl get replicasetsreturnsDESIRED 3 CURRENT 3 READY 3; the three Pods with the sametest-nginx-5fd56bf67bprefix belong to one ReplicaSet. That hash is generated from the pod template, and changing the image produces a new ReplicaSet with the same Deployment name but a different hash. Consequence: when a Deployment is "stuck" mid-rollout, the right place to look iskubectl get replicasets(you see the old and new ReplicaSets coexisting), not justkubectl get deployment. - When it breaks: Manually deleting a ReplicaSet without deleting the Deployment that owns it makes the Deployment recreate a new ReplicaSet immediately, because the Deployment continuously watches its child ReplicaSets.
- In real deployments: Read
kubectl rollout statusandkubectl get rswhen a rollout hangs, and do not guess the cause from the current Pod count alone.
- Why: A ReplicaSet identifies the Pods that belong to it through a label selector and keeps exactly
-
A Service binds to labels through a selector, not to a Deployment
- Why: A Service picks Pods by label selector; the EndpointSlice/Endpoints record the list of Pod IPs that match that selector, independent of the Deployment name (Kubernetes: Service, Kubernetes: EndpointSlices). Measured on the lab cluster on 2026-09-17:
kubectl get endpoints test-nginxafter expose returns exactly three Pod IPs10.244.1.4:80,10.244.1.5:80,10.244.2.5:80, and there is no reference to the Deployment name anywhere in the Service object. Consequence: the Service keeps working even if the Deployment is deleted and another bare Pod with the same label is created by hand; "empty endpoints" is the first thing to read when a Service is "unreachable", rather than checking the Deployment. - When it breaks: Changing the label in the Pod template but forgetting to change the Service's
selectormakes the Endpoints empty immediately: the Service behaves as if no Pod is behind it even though the Pods are Running. - In real deployments: Always check
kubectl get endpoints <svc>first when a Service reports connection errors; empty endpoints point straight to a mismatched selector/label.
- Why: A Service picks Pods by label selector; the EndpointSlice/Endpoints record the list of Pod IPs that match that selector, independent of the Deployment name (Kubernetes: Service, Kubernetes: EndpointSlices). Measured on the lab cluster on 2026-09-17:
-
A NodePort is open on every node, not only the node that has the Pod
- Why: kube-proxy sets up DNAT rules on EVERY node for every NodePort Service, including nodes that host no Pod of that service (Kubernetes: virtual IPs and service proxies). Measured on the lab cluster on 2026-09-17: port
31846of the Servicetest-nginxis open on all three nodes, includingcp-1, which runs no Pod of the service; all three curl calls to the three nodes returned HTTP 200. Consequence: checking a NodePort does not require knowing which node the Pod is on; an external healthcheck or load balancer can point at any node in the cluster and still be correct. - When it breaks: Reasoning that a NodePort is open only on the node that holds the Pod leads to a load balancer configured to point at a single node, losing fault tolerance when exactly that node goes down.
- In real deployments: Point the external load balancer at all nodes in the cluster, not just the node known to have a Pod, because kube-proxy DNAT works the same way on every node.
- Why: kube-proxy sets up DNAT rules on EVERY node for every NodePort Service, including nodes that host no Pod of that service (Kubernetes: virtual IPs and service proxies). Measured on the lab cluster on 2026-09-17: port
-
Self-healing creates a new Pod; it does not resurrect the old one
- Why: A ReplicaSet tracks the actual Pod count through a watch and creates a new Pod when the number of Pods matching the selector drops below
spec.replicas(Kubernetes: ReplicaSet). A deleted Pod is a permanent termination event, not a pause. Measured on the lab cluster on 2026-09-17: the Podtest-nginx-5fd56bf67b-jcs99was deleted at 14:57:16; 8 seconds later (14:57:24) a new Podtest-nginx-5fd56bf67b-mcggbappeared with a completely different IP10.244.2.6, on nodeworker-2instead of the oldworker-1. Consequence for application design: treat a Pod as a disposable resource. Local state inside the container (temp files, in-memory sessions) is lost when the Pod is replaced; what lasts is the Deployment (the description) and the Service (the stable address), not the Pod itself. - When it breaks: Storing important state only in the container's filesystem without an external volume, then expecting it to survive the next self-heal. The new Pod starts again from the original image and inherits nothing from the old Pod.
- In real deployments: An application that must keep state has to use a PersistentVolume or store its state outside the Pod; the recovery time (the 8 seconds measured here) is a parameter to factor into availability SLA calculations.
- Why: A ReplicaSet tracks the actual Pod count through a watch and creates a new Pod when the number of Pods matching the selector drops below
-
NodePort traffic is distributed randomly per connection, not in even round-robin
- Why: kube-proxy in iptables mode picks the destination endpoint with a
statistic mode randomrule: random for each new connection, not a perfectly balanced round-robin (Kubernetes: proxy-mode iptables). The defaultexternalTrafficPolicy: Clusterlets traffic arriving at one node be forwarded to a Pod on another node, in exchange for the source IP being SNATed (Kubernetes: traffic policies). Measured on the lab cluster on 2026-09-17: the first three curl calls tohello-appall hit the same Podzphz2, a coincidence of a small sample. Measured again with 30 requests to one node's NodePort: 11 went to Podm9dr7and 19 tozphz2; with 30 requests alternating across all three nodes: 14/16. Consequence: do not conclude anything about the distribution mechanism from a few curl calls; you need a large enough measurement (30 here) to see that the imbalance between the two Pods falls within a reasonable random range and is not evidence of a load balancing fault. - When it breaks: Concluding that "load balancing is skewed" from 3 curl calls hitting the same Pod sends the investigation in the wrong direction; the phenomenon disappears when the sample is increased to 30.
- In real deployments: A benchmark or healthcheck that relies on NodePort/ClusterIP traffic distribution must use enough samples (dozens or more) before concluding that the iptables proxy has a problem.
- Why: kube-proxy in iptables mode picks the destination endpoint with a
-
Four Pod failures have four different ways to diagnose
- Why: For
ImagePullBackOff,describeshows the Pod was already Scheduled and only then failed to pull the image (Kubernetes: ImagePullBackOff);Error/CrashLoopBackOffare told apart byrestartPolicyand by reading RESTARTS (Kubernetes: restart policy); forPending, read theFailedSchedulingpart of Events, and logs are meaningless (Kubernetes: pod phase); for taints, readspec.nodeNameandkubectl get node -o jsonpath='{.spec.taints}'(Kubernetes: taints and tolerations). Measured on the lab cluster on 2026-09-17: four test Pods (badimage,crasher/crashloop,toobig,pinned) illustrate exactly these four branches using four different fields indescribe/get -o jsonpath, not one single command. Consequence: a generic diagnostic checklist ('get pod' and then guess) is not enough to tell the four failures apart; each failure needs exactly one different data field. - When it breaks: Applying the same 'delete the Pod and recreate it' action to all four failures hides the root cause. The recreated Pod repeats exactly the same failure because the faulty configuration (image tag, RAM request, taint) has not changed.
- In real deployments: An incident runbook should split the four diagnostic branches by the observable STATUS and lead straight to the data field to read, instead of trying each hypothesis in turn.
- Why: For
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:
kubectl exec -it <pod> --bashreports an error as soon as you type it: kubectl parses--bashas a flag of its own and reportsunknown flag: --bash, never having touched the container.
How to fix:
-
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:
- STATUS ImagePullBackOff, READY 0/1: the Events progress through ErrImagePull → BackOff → ImagePullBackOff, along with the message
unexpected media type text/htmlfrom mirror.gcr.io.
How to fix:
-
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:
kubectl logs --previousreportsunable to retrieve container logs: containerd had already cleaned up the old container before the command ran, so pod crashloop-59b4db4cd-hsfd5 lost the previous run's log even though RESTARTS had increased.
How to fix:
-
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:
- The Pod stays Pending and no container exists: the FailedScheduling event lists all 3 nodes: 1 control-plane taint, 2 Insufficient memory (3911 MiB per node, the pod asks for 64 GiB).
How to fix:
-
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
- Wrong:
kubectl scale deployment --replicas=3increases the number of containers running inside one Pod. Right:--replicas=3creates three independent Pods, each still with exactly one container; the READY column of each Pod still reads 1/1.
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.
- Wrong:
kubectl exec -it <pod> --bashopens an interactive shell inside the Pod. Right: The correct syntax has two dashes, a space, then the command name:kubectl exec -it <pod> -- bash. Writing--bashjoined together is read by kubectl as a nonexistent flag.
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.
- Wrong: STATUS
Errorand STATUSCrashLoopBackOffare two names for the same incident. Right: These two STATUS values differ in the Pod'srestartPolicy:Errorcorresponds torestartPolicy: Never(the container stops for good, andRESTARTSstays at 0 forever);CrashLoopBackOffappears when the kubelet is still allowed to restart the container, meaningrestartPolicyisAlwaysOROnFailure, and it is waiting out the backoff period.
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.
- Wrong:
kubectl logsalways tells you why a Pod is not running yet. Right: A Pod in STATUSPendinghas no container created yet, sokubectl logshas nothing to read; the cause is in the Events section ofkubectl describe pod.
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.
- Wrong: A
NoScheduletaint on the control plane node always prevents every Pod from running on that node. Right:NoScheduleis only a rule that kube-scheduler applies when choosing a node for a new Pod. A Pod that declaresspec.nodeNamedirectly bypasses the scheduler and can run on the tainted node itself.
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:
kubectl exec -it <pod> --bashreports unknown flag: Add a space:kubectl exec -it <pod> -- bash. Everything after--is the command/arguments for the container.
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:
kubectl get endpointsreturns empty: Check whether the Service'sselectormatches thelabelsof the Pod template; a selector/label mismatch is the direct cause of empty endpoints.
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:
- Old Pods still exist after deleting the Deployment: Check whether that Pod has an OwnerReference pointing to the ReplicaSet that was deleted; a Pod created by hand (not through a Deployment) is not deleted along with it.
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:
- Not sure of each node's real available RAM for adjusting requests.memory: The total RAM per node on the lab cluster is 3911 MiB (evidence §0), but
allocatableis always lower than capacity because kube-reserved, system-reserved and the eviction threshold have been subtracted. Runkubectl get node -o custom-columns=NAME:.metadata.name,MEM:.status.allocatable.memoryto get the real number before settingrequests.memory.
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?
- 3/3, which proves each Pod now has 3 containers
- 1/1 on all three Pods, which proves --replicas creates additional Pods and does not add containers to the old Pod
- 0/1, the Pod is not ready right after the scale
- 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.
- READY 3/3 would only happen if 3 containers were in 1 Pod, which is not what
--replicasdoes; 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?
- kubectl exec -it <pod> --bash
- kubectl exec -it <pod> -- bash
- kubectl exec <pod> --shell bash
- 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.
--bashjoined 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?
- Both are CrashLoopBackOff because of the same application error
- crasher stays at Error with RESTARTS=0 forever; crashloop oscillates between Error and CrashLoopBackOff with RESTARTS rising
- crasher recovers on its own after a few seconds
- 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.
- 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)?
- badimage has no Scheduled event, toobig does
- badimage has a successful Scheduled event and then fails to pull the image; toobig never had a successful Scheduled event
- Neither has any event
- 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.
- 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?
- Because the logs were cleaned up by the runtime
- Because the Pod is Pending, so no container has been created to produce logs
- Because toobig runs on the tainted control plane node
- 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.
- 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?
- The NoSchedule taint is only considered by kube-scheduler when choosing a node; declaring nodeName directly bypasses the scheduler
- The taint applies only to Deployments, not to bare Pods
- pinned has a hidden default toleration
- 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.
- 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?
- 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
- A static Pod always has a default toleration for every taint
- Taints apply only after the cluster has been running for a certain amount of time
- 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.
- 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?
- The Deployment name
test-nginx, since the Service follows the Deployment name - 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
- Empty until the Deployment finishes scaling
- 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.
- 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?
- kube-proxy splits perfectly evenly at 15/15 every time
- The first three curl calls hitting the same Pod prove that a NodePort always sticks to one Pod
- 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
- 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.
- 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
-
What does
--replicas=3create? 3 independent Pods, each still with 1 container, not 3 containers in 1 Pod. The READY column of each Pod is still 1/1 after the scale; the ReplicaSet's DESIRED/CURRENT/READY count Pods, not containers. -
What is the correct kubectl exec syntax to run bash?
kubectl exec -it <pod> -- bash: two dashes, a space, then the command name.--bashjoined without a space is read by kubectl as a flag of its own and reports unknown flag. -
How does Error differ from CrashLoopBackOff? restartPolicy: Never gives Error, with RESTARTS=0 forever. Always (the Deployment default) and OnFailure both give an oscillating CrashLoopBackOff with RESTARTS rising; Never is the only one that never shows CrashLoopBackOff. crasher (--restart=Never) stays at Error forever; crashloop (through a Deployment) oscillates between Error/CrashLoopBackOff across the t+20s...t+100s marks.
-
What does kubectl logs give for a Pending Pod? Nothing to read: Pending means no container has been created yet. The correct diagnosis is to read Events in kubectl describe pod, not logs.
-
What does the FailedScheduling event of the toobig Pod say? 0/3 nodes available: 1 node with the control-plane taint, 2 nodes with insufficient memory. The Pod asks for requests.memory: 64Gi while each node has only 3911 MiB.
-
What does a NoSchedule taint block? Only the kube-scheduler's decision. A Pod that declares nodeName directly bypasses the scheduler and so is not blocked. The pinned Pod runs Running on the tainted node by declaring spec.nodeName directly.
-
Why can a static Pod (etcd, apiserver) run on a tainted control plane node? The kubelet reads the manifest straight from /etc/kubernetes/manifests, without going through the scheduler. A taint is a scheduler rule, not a kubelet gate.
-
What do a Service's Endpoints point to? The real list of IP:port of the Pods matching the label selector, with no reference to the Deployment name. Empty endpoints are the first sign when a Service cannot route traffic.
-
Which nodes is a NodePort open on? Every node in the cluster, including nodes that run no Pod of that service. kube-proxy sets up DNAT rules on all nodes, not only the node that has the Pod.
-
How long after deleting a Pod does the ReplicaSet create a new one? 8 seconds in the measurement on the lab cluster; the new Pod has a different name, a different IP, and may be on a different node. Self-healing creates a new Pod; it does not resurrect the old one.
-
Why did the first three curl calls to the hello-app NodePort all hit the same Pod? A coincidence of a small sample; only measuring 30 requests revealed the 11/19 and 14/16 distributions between the two Pods. kube-proxy in iptables mode picks the endpoint at random per connection, not in even round-robin.
-
What is the default externalTrafficPolicy of a Service, and what is the consequence? Cluster: a request can be forwarded to a Pod on another node, in exchange for the source IP being SNATed. An application behind a NodePort cannot see the real client IP when traffic passes through a node other than the one holding the Pod.
-
Does kubectl logs --previous always show the previous run's log? No. The old container may already have been cleaned up by containerd before the command ran. Evidence: crashloop-59b4db4cd-hsfd5 reported
unable to retrieve container logswhen --previous was called. -
What does a Container ID of the form containerd://... in describe pod prove? The runtime that actually created the container is containerd, not Docker. The kubelet calls containerd through the CRI; Docker is just another client that shares containerd on the node.
-
What does the Pod IP 10.244.2.5 say about the Pod's location? It lies in 10.244.2.0/24, the range the controller-manager assigned to node worker-2. Reading the octet of a Pod IP tells you right away which node the Pod is on without running get -o wide.