Control Plane Overview
When you run kubectl, a complex series of interactions happens behind the scenes. Understanding this flow helps you debug issues and understand how Kubernetes orchestrates your applications.
What Happens When You Run kubectl
Let's trace a simple command: kubectl create deployment nginx --image=nginx:1.21
Step 1: kubectl Processes the Command
kubectl create deployment nginx --image=nginx:1.21
What kubectl does:
- Parses the command and flags
- Constructs an API request (HTTP POST to
/apis/apps/v1/namespaces/default/deployments) - Reads your kubeconfig file for authentication
- Sends the request to the API Server
Step 2: Request Reaches API Server
The API Server is the central hub for all Kubernetes operations.
What happens:
- Authentication: Verifies who you are (certificate, token, or basic auth)
- Authorization: Checks if you have permission to create deployments (RBAC)
- Admission Control: Validates and potentially mutates the request (ValidatingAdmissionWebhooks, MutatingAdmissionWebhooks)
- Schema Validation: Ensures the object structure is correct
If validation fails:
- Request is rejected with an error message
- You see the error in
kubectloutput
If validation succeeds:
- Object is stored in etcd
- API Server returns success response to kubectl
Step 3: etcd Stores the State
etcd is the source of truth for all cluster data.
- The Deployment object is written to etcd
- etcd notifies watchers (controllers) about the change
- The change is persistent and survives API Server restarts
Step 4: Controllers React
Multiple controllers watch for changes via the API Server:
Deployment Controller
- Notices the new Deployment object
- Creates a ReplicaSet to manage pod replicas
- Sets desired replica count based on Deployment spec
ReplicaSet Controller
- Notices the new ReplicaSet
- Compares desired replicas vs actual pod count
- Creates Pod objects (but they're not scheduled yet)
Pod objects at this stage:
- Have no
nodeNameassigned - Status:
Pending - Waiting for scheduler
Step 5: Scheduler Assigns Pods to Nodes
The Scheduler watches for pods without a node assignment.
Scheduling Process:
Filtering Phase:
- Check if node has enough resources (CPU, memory)
- Check node selector matches
- Check taints/tolerations
- Check pod affinity/anti-affinity rules
Scoring Phase:
- Score remaining nodes based on:
- Resource availability
- Affinity preferences
- Spread constraints (distribute pods across nodes/zones)
- Score remaining nodes based on:
Binding:
- Selects highest-scoring node
- Updates pod with
nodeName: <selected-node> - Writes binding to API Server
Step 6: kubelet Creates Containers
The kubelet on the assigned node:
Watches API Server for pods assigned to its node
Pulls Container Image from the registry
Creates Pod Runtime Environment:
- Sets up network namespace
- Mounts volumes
- Creates container runtime specification
Starts Containers using container runtime (containerd, CRI-O, etc.)
Reports Status back to API Server:
- Pod phase:
Running - Container statuses
- Resource usage
- Pod phase:
Step 7: kube-proxy Updates Networking
kube-proxy on each node:
- Watches for Service and Endpoint changes
- Updates iptables/IPVS rules
- Enables service discovery and load balancing
Visual Flow Diagram
┌─────────┐
│ kubectl │
└────┬────┘
│ HTTP POST /apis/apps/v1/deployments
▼
┌──────────────────┐
│ API Server │ ◄─── Authentication
│ │ ◄─── Authorization
│ │ ◄─── Validation
└────┬─────────────┘
│ Write to etcd
▼
┌─────────┐
│ etcd │ ◄─── Persistent storage
└────┬────┘
│ Notify watchers
▼
┌─────────────────────┐
│ Deployment Controller│ ──► Creates ReplicaSet
└─────────────────────┘
│
▼
┌──────────────────┐
│ ReplicaSet │ ──► Creates Pods (no node)
│ Controller │
└──────────────────┘
│
▼
┌──────────────┐
│ Scheduler │ ──► Assigns Pod to Node
└──────────────┘
│
▼
┌─────────┐
│ kubelet │ ──► Creates containers
└─────────┘
│
▼
┌──────────┐
│ Pod │ ──► Running
│ Running │
└──────────┘
Request Types
Write Operations (Create, Update, Delete)
kubectl → API Server → etcd → Controllers → Nodes
Read Operations (Get, List, Watch)
kubectl ← API Server ← etcd
Reads are fast because they come directly from etcd via the API Server.
Watch Operations
kubectl ← API Server ← etcd (continuous updates)
kubectl get pods -w establishes a long-lived connection for real-time updates.
Common kubectl Commands and Their Paths
kubectl get pods
- kubectl sends GET request to API Server
- API Server queries etcd
- Returns list of pods
- kubectl formats and displays
kubectl logs <pod>
- kubectl requests logs from API Server
- API Server forwards request to kubelet on pod's node
- kubelet reads logs from container runtime
- Returns logs through API Server to kubectl
kubectl exec -it <pod> -- /bin/bash
- kubectl establishes exec connection
- API Server proxies connection to kubelet
- kubelet executes command in container
- Streams stdin/stdout back
kubectl apply -f file.yaml
- kubectl reads and parses YAML
- Converts to API objects
- Sends to API Server (POST/PATCH)
- Same flow as create/update above
Debugging the Request Path
See API Requests
# Verbose output shows API calls
kubectl get pods -v=8
Check API Server Logs
# View API Server logs (requires access)
kubectl logs -n kube-system kube-apiserver-<node>
Verify Objects in etcd
# Requires etcdctl access
etcdctl get /registry/deployments/default/nginx
Watch Events
# See events as they happen
kubectl get events --watch
# View events for a specific resource
kubectl describe pod <pod-name>
Key Takeaways
- Everything goes through API Server - It's the single entry point
- etcd is the source of truth - All state is stored there
- Controllers react to changes - They continuously reconcile state
- Scheduler assigns pods - Based on resource and policy constraints
- kubelet runs containers - It's the bridge between API Server and containers
- Operations are eventually consistent - Changes propagate through the system
Understanding this flow helps you:
- Debug why pods aren't starting
- Understand why resources aren't updating
- Know where to look when things go wrong
- Design applications that work well with Kubernetes
This is the foundation of how Kubernetes orchestrates your applications!