Sub topic 16
Tracing a Deployment from kubectl apply to running containers
This chapter assumes you know the control plane components (API server, etcd, scheduler, controller manager), the kubelet, and the Deployment, ReplicaSet, and Pod objects. Here you follow one request through all of them.
The path in order
Suppose deployment.yaml declares a Deployment named web with three replicas of nginx:1.27. You run the apply command.
kubectl apply -f deployment.yaml
kubectl get deployments
kubectl get pods -o wide- kubectl reads the file and sends it to the API server over HTTPS.
- The API server authenticates and authorizes the request, validates the object, and writes it to etcd.
- The Deployment controller sees the new Deployment and creates a ReplicaSet.
- The ReplicaSet controller sees that zero Pods exist and three are wanted, so it creates three Pod objects.
- The scheduler finds Pods with no node assigned. It picks a node for each one and writes the choice into the Pod's
nodeName. - The kubelet on each chosen node sees a Pod bound to it. It asks the container runtime, through the CRI, to pull the image and start the containers.
- The kubelet reports status back to the API server, and
kubectl get podsshowsRunning.
No component calls another directly. Each one watches the API server and reacts to changes. The API server is the only component that reads and writes etcd.
Observing the trace
The events list records the steps in order.
kubectl describe pod <pod-name>
kubectl get events --sort-by=.metadata.creationTimestampLook for Scheduled (from the scheduler), then Pulling, Pulled, Created, and Started (from the kubelet).
Common errors and where they stop the trace
| Symptom | Stage that failed | Typical cause |
|---|---|---|
| `apply` is rejected | API server | Invalid YAML, unknown field, or no RBAC permission |
| Pod stays `Pending` | Scheduler | No node has enough CPU or memory, or taints and selectors exclude every node |
| `ImagePullBackOff` | Kubelet and runtime | Wrong image name or tag, or missing registry credentials |
| `CrashLoopBackOff` | Running container | The application exits right after it starts |
Exercise
A Pod appears in kubectl get pods with status Pending, and its nodeName field is empty. Which component has not yet acted, and which earlier steps must have succeeded?
Show answer
The scheduler has not yet assigned a node. The API server must have accepted and stored the Deployment, and the Deployment and ReplicaSet controllers must have created the ReplicaSet and the Pod. Check kubectl describe pod for a scheduling event, such as insufficient resources.