Skip to content

How a pod gets from YAML to running

Draft: not yet run against a live cluster. Treat output as representative and check it on yours.

When a pod is stuck, the useful question is never “why is Kubernetes broken?” It is “which component stopped making progress?” This chapter gives you the map to answer that in under a minute.

  1. The API server accepts the pod. Your request is authenticated, authorized by RBAC, passed through mutating admission (which can inject defaults, sidecars, or labels), validated against the schema, then passed through validating admission (which can reject it). Only then is it stored in etcd. The pod now exists with phase Pending and no node.

    If you created a Deployment, there’s one more hop: the Deployment controller creates a ReplicaSet, and the ReplicaSet controller creates the pods. A rejected pod there shows up as an event on the ReplicaSet, not as an error from kubectl apply.

  2. The scheduler picks a node. It filters out every node that can’t run the pod: not enough unreserved CPU or memory for the pod’s requests, a nodeSelector or affinity rule that doesn’t match, or a taint the pod doesn’t tolerate. It scores the nodes that remain and binds the pod to the best one by setting spec.nodeName. The PodScheduled condition becomes True.

    If no node passes the filters, the pod stays Pending, PodScheduled is False with reason Unschedulable, and the scheduler records a FailedScheduling event. It retries when something in the cluster changes.

  3. The kubelet builds the sandbox. The kubelet on the chosen node sees the binding and asks the container runtime (containerd or CRI-O) to create a pod sandbox. That’s a small pause container that holds the pod’s network namespace. The runtime calls the CNI plugin to attach the pod to the network and assign its IP. Volumes are mounted here too.

  4. Images are pulled and containers start. Images are pulled according to imagePullPolicy. Init containers run one at a time, and each must exit 0 before the next starts. Then the app containers start.

  5. Probes decide when the pod is useful. If a startup probe is defined, liveness and readiness checks wait until it succeeds. Readiness controls the pod’s Ready condition, which decides whether Services send it traffic. A failed liveness probe makes the kubelet restart the container.

kubectl get pods shows a STATUS column that looks like the phase but isn’t. kubectl computes it from several fields, and it usually shows a container’s waiting or terminated reason. A pod showing CrashLoopBackOff is normally in phase Running.

Phase Means
Pending Accepted, but at least one container isn’t running yet. Includes waiting for a node, pulling images, and running init containers.
Running Bound to a node, and at least one container is running, starting, or restarting.
Succeeded Every container exited 0 and won’t restart.
Failed Every container has stopped, and at least one exited non-zero or was killed.
Unknown The control plane can’t get status from the node, usually because the kubelet is unreachable.

Read the real state with:

Terminal window
kubectl get pod web -o jsonpath='{.status.phase}{"\n"}'
kubectl get pod web -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.reason}{"\n"}{end}'
kubectl get pod web -o jsonpath='{range .status.containerStatuses[*]}{.name}: {.state}{"\n"}{end}'

Create a cluster and a deployment with requests and a readiness probe:

Terminal window
kind create cluster --name lifecycle
web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 1
selector:
matchLabels: { app: web }
template:
metadata:
labels: { app: web }
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
resources:
requests: { cpu: 100m, memory: 64Mi }
limits: { memory: 64Mi }
readinessProbe:
httpGet: { path: /, port: 80 }
periodSeconds: 5

Apply it and watch each component do its job:

Terminal window
kubectl apply -f web.yaml
kubectl get pods -l app=web -w
kubectl get events --sort-by=.lastTimestamp

In the events you’ll see the sequence from the steps above: Scheduled (scheduler), Pulling and Pulled (kubelet), Created and Started (kubelet via the runtime). Clean up with kind delete cluster --name lifecycle.

kubectl get pods shows CrashLoopBackOff. What is the pod's phase, most likely?

Running. The STATUS column shows the container’s waiting reason, not the phase. The pod is bound and its container is restarting, which counts as Running.

Which field does the scheduler set, and how can you check whether it has done its job?

spec.nodeName, written through a binding. If kubectl get pod <pod> -o jsonpath='{.spec.nodeName}' returns a node name, scheduling is done and the problem is on that node.

Does the scheduler use requests, limits, or actual usage?

Requests. It compares the sum of requests on each node with the node’s allocatable capacity. Limits and real usage don’t affect scheduling.

A pod has been in ContainerCreating for ten minutes. Scheduler problem or node problem?

Node problem. ContainerCreating means the pod is already bound. Look at its events for sandbox, mount, or image pull errors from the kubelet.

What is the difference between a failing readiness probe and a failing liveness probe?

A failing readiness probe removes the pod from Service endpoints but leaves the container running. A failing liveness probe makes the kubelet kill and restart the container.

Maps to: CKA: Workloads and Scheduling; CKA: Troubleshooting. Check the current exam curriculum, since domain names change between revisions.