Kubernetes Field Guide · Chapter 2 of 16
Inside a cluster: the path of a kubectl apply
A cluster is a handful of components that never call each other directly. They all watch one API server and react. Learn who does what, follow a kubectl apply end to end, and find every piece in your own cluster.
- 30 min
- Beginner
- Hands-on
- Free
By Joshua Sequeira, founding engineer running Kubernetes in production. Updated .
By the end you can
0 of 4
Live lab in this chapter
A real-feeling terminal and a live cluster map, right in your browser. Every command block below has a ▶ Run in lab button.
Two halves: the control plane decides, the nodes run
Every cluster has two parts. The control plane stores the desired state and decides what should run where. The worker nodes are the machines that actually run your containers.
One rule explains most of the design: components never call each other directly. Each one watches the API server for changes it cares about, does its job and writes the result back. That is how a scheduler, a dozen controllers and hundreds of kubelets stay in step without knowing about each other.
Interactive
Cluster map
You
Control plane
Worker node-1
Worker node-2
Click a component, or press play
Two halves: the control plane decides, the nodes run.
Everything goes through the API server. Components never call each other directly: they watch the API server and react.
The control plane
- kube-apiserver is the front door. kubectl, controllers, the scheduler and every kubelet talk only to it. Each request is authenticated, checked against RBAC, passed through admission controllers and validated.
- etcd is a consistent key-value store holding every object in the cluster. Only the API server talks to it. Back it up: without etcd there is no cluster.
- kube-scheduler picks a node for each new pod. It filters out nodes that cannot run it (not enough CPU or memory, taints, affinity rules), scores the rest and records its choice.
- kube-controller-manager runs the control loops from chapter 1: Deployments, ReplicaSets, Nodes, Jobs and more, each reconciling desired with actual state.
On a cloud provider there is often a fifth, the cloud-controller-manager, which creates load balancers and attaches disks through the provider's API.
Worker nodes
- kubelet is the agent on every node. It watches for pods bound to its node, starts their containers, runs health checks and reports status.
- Container runtime, usually containerd, pulls images and runs containers. The kubelet talks to it through the Container Runtime Interface (CRI).
- kube-proxy programs network rules so traffic sent to a Service reaches a healthy pod. Some network plugins, such as Cilium, replace it.
A network plugin (CNI) gives every pod its own IP address and lets pods on different nodes reach each other. kind uses one called kindnet.
What happens on kubectl apply
Nothing in Kubernetes calls anything else directly. Every component watches the API server and reacts to changes. Step through one kubectl apply and watch the work pass from component to component:
Step through it
One kubectl apply, from your laptop to a running container
- kubectlyour laptop
- API servercontrol plane
- etcdcontrol plane
- Controllerscontroller manager
- Schedulercontrol plane
- Kubeleton the node
- containerdon the node
Step 0 of 9
Press Play, or step through with Next.
Knowing that path turns error messages into directions:
| Symptom | Suspect first |
|---|---|
| kubectl says connection refused or Unauthorized | API server address or credentials in your kubeconfig |
| Pod stuck in Pending, no node | Scheduler: resources, taints, affinity |
| Pod stuck in ContainerCreating | Kubelet on that node: volumes, network plugin, image pull |
| ErrImagePull or ImagePullBackOff | Runtime and registry: image name, tag, credentials |
| Pods run but the Service gets no traffic | Service selector and labels, then kube-proxy |
When a component stops
Knowing who does what pays off when something breaks. Each component has one job, so each failure has its own signature: some take out kubectl, some only stop new pods, some you would not notice for minutes. Stop one at a time and read what still works.
Interactive
Stop a component. What still works?
Control plane
Nodes
Everything is running. Click a component to stop it.
Running apps keep serving traffic
kubectl get and apply work
New pods get placed on a node
Crashed or deleted pods are replaced
Apps find each other by name
The pattern worth remembering: running workloads are surprisingly hard to kill. Almost every control plane failure freezes the cluster in its current state rather than tearing it down. What stops is change: new pods, replacements, scaling, deploys.
Hands-on: find every component
The lab is docked at the bottom of your screen.
Live lab · no install
Find every component
Look under the hood of a running kind cluster and trace who did what.
- Tasks0/6
Find the control plane
Tick "system" above the map to see these pods on the node.
kubectl cluster-infoList every cluster component
The API server, etcd, scheduler and controller manager run as pods in kube-system.
kubectl get pods -n kube-systemNames ending in -learn-control-plane are static pods, started by the kubelet from files on the node.
Check the kubelet, which is not a pod
kind nodes are Docker containers, so you can look inside one.
docker exec learn-control-plane systemctl is-active kubeletAsk the runtime what it is running
crictl talks to containerd directly, the same way the kubelet does.
docker exec learn-control-plane crictl ps --name nginxScale web to 4 and see who did what
Events record every component that touched the new pod.
kubectl scale deployment web --replicas=4 sleep 3 kubectl get events --sort-by=.metadata.creationTimestamp | tail -n 6SuccessfulCreate: the ReplicaSet controller. Scheduled: the scheduler. Pulled and Started: the kubelet.
Read the newest pod from top to bottom
describe ends with the same story, for one pod.
kubectl describe $(kubectl get pods -l app=web --sort-by=.metadata.creationTimestamp -o name | tail -n 1)- Lab complete. Keep experimenting, or press Reset to start again.
- ready
- starting / not ready
- failing
- terminating
Prefer your own machine? The same steps on a local cluster
Use the learn cluster from chapter 1. In kind, one node runs both halves, so you can see everything at once.
kubectl cluster-info
kubectl get pods -n kube-system
Kubernetes control plane is running at https://127.0.0.1:52813
CoreDNS is running at https://127.0.0.1:52813/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
NAME READY STATUS RESTARTS AGE
coredns-7c65d6cfc9-8xw2m 1/1 Running 0 1h
coredns-7c65d6cfc9-tqv6n 1/1 Running 0 1h
etcd-learn-control-plane 1/1 Running 0 1h
kindnet-9k4lf 1/1 Running 0 1h
kube-apiserver-learn-control-plane 1/1 Running 0 1h
kube-controller-manager-learn-control-plane 1/1 Running 0 1h
kube-proxy-r2b7d 1/1 Running 0 1h
kube-scheduler-learn-control-plane 1/1 Running 0 1h-n kube-system- The namespace where cluster components live.
-learn-control-plane- Control plane components run as static pods, named after their node.
coredns- Cluster DNS, so pods can find Services by name (chapter 5).
The kubelet is missing from that list because it is not a pod. kind nodes are Docker containers, so you can look inside one:
docker exec learn-control-plane systemctl is-active kubelet
docker exec learn-control-plane crictl ps --name nginx
active
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD
3f1c2a9e8b7d4 a830707172e8 2 hours ago Running nginx 0 9e1d7c3b2a6f5 web-6c9b8d7f5d-9qmzt
...systemctl is-active kubelet- The kubelet runs as a systemd service on the node.
crictl ps- Asks containerd directly, the same way the kubelet does.
Finally, see the components at work. Events record who did what:
kubectl get events --sort-by=.metadata.creationTimestamp | tail -n 5
LAST SEEN TYPE REASON OBJECT MESSAGE
5m Normal ScalingReplicaSet deployment/web Scaled up replica set web-6c9b8d7f5d from 2 to 3
5m Normal SuccessfulCreate replicaset/web-6c9b8d7f5d Created pod: web-6c9b8d7f5d-zc8hn
5m Normal Scheduled pod/web-6c9b8d7f5d-zc8hn Successfully assigned default/web-6c9b8d7f5d-zc8hn to learn-control-plane
5m Normal Pulled pod/web-6c9b8d7f5d-zc8hn Container image "nginx:1.27" already present on machine
5m Normal Started pod/web-6c9b8d7f5d-zc8hn Started container nginxSuccessfulCreate- The ReplicaSet controller (controller manager).
Scheduled- The scheduler.
Pulled, Started- The kubelet and container runtime.
Add -v=6 to any kubectl command to see the HTTPS calls it makes to the API server. The log format varies between kubectl versions.
Mini mission
Name who did it
Scale web to four replicas. For the new pod, find which component created it, which one chose its node and which one started its container.
Reveal one safe solution
kubectl scale deployment web --replicas=4
kubectl describe $(kubectl get pods -l app=web --sort-by=.metadata.creationTimestamp -o name | tail -n 1)
The Events at the bottom show default-scheduler for Scheduled and kubelet for Pulled, Created and Started. The pod's Controlled By line names its ReplicaSet, whose controller created it. Scale back with kubectl scale deployment web --replicas=3.
Check yourself
Quiz
0 of 4 answered