PART 1: CORE THEORY
1. The Control Plane
The control plane is the brain of Kubernetes. It makes all the decisions: what runs where, how many replicas, what happens when something fails. It consists of four components that work together.
The Four Components
text
┌─────────────────────────────────────────────────────────────┐
│ CONTROL PLANE COMPONENTS │
│ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ kube- │ │ etcd │ │
│ │ apiserver │◄───►│ (State DB) │ │
│ │ (REST API) │ │ Raft quorum │ │
│ └───────┬───────┘ └───────────────┘ │
│ │ │
│ │ │
│ ┌───────┴───────┐ ┌───────────────┐ │
│ │ kube- │ │ kube- │ │
│ │ scheduler │ │ controller- │ │
│ │ (Filter → │ │ manager │ │
│ │ Score → │ │ (Reconcile) │ │
│ │ Bind) │ │ │ │
│ └───────────────┘ └───────────────┘ │
└─────────────────────────────────────────────────────────────┘
Component Responsibilities
| Component | Role | Stateful? |
| kube-apiserver | REST API, the only component that talks to etcd | Stateless |
| etcd | Key-value store, the single source of truth | Stateful |
| kube-scheduler | Assigns Pods to Nodes | Stateless |
| kube-controller-manager | Runs reconciliation loops | Stateless |
The Key Insight
Only the API server talks to etcd. Everything else talks to the API server. This is the fundamental design pattern.
2. The API Server
kube-apiserver is the front door to Kubernetes. Every kubectl command, every controller action, every kubelet heartbeat goes through it.
The Request Flow (Step by Step)
When a request hits the API server:
text
Request → Authentication → Authorization → Admission → etcd
│ │ │
▼ ▼ ▼
Who are you? Are you allowed? Should we
modify it?
Step 1: Authentication (AuthN)
The API server verifies identity using:
- TLS client certificates
- Service account tokens (JWTs)
- OIDC tokens
- Webhook authenticators
- Cloud IAM (AWS IAM, GCP IAM)
Step 2: Authorization (AuthZ)
The API server checks permissions using:
- RBAC (most common)
- ABAC (legacy)
- Node authorization
- Webhook authorization
Kubernetes authorization takes place after authentication. Usually, a client making a request must be authenticated before its request can be allowed; however, Kubernetes also allows anonymous requests in some circumstances.
Step 3: Admission Control
Admission controllers intercept requests after authentication and authorization but before persistence to etcd.
Admission control proceeds in two phases:
- Mutating admission controllers run first. They can modify the object.
- Validating admission controllers run second. They can only allow or deny.
A mutating webhook can change the object before it's saved, while a validating admission webhook can only allow or deny it. This ordering matters because mutations always run first, so validation sees the final version of the object.
Step 4: Persistence
If the request passes all checks, the API server writes it to etcd.
API Server Aggregation
The aggregation layer allows Kubernetes to be extended with additional APIs beyond what the core Kubernetes APIs offer. It runs in-process with the kube-apiserver.
This is how metrics-server, custom metrics, and other extension APIs work.
3. etcd
etcd is a distributed, reliable key-value store that serves as the single source of truth for all cluster state. If etcd is lost, the cluster is lost.
Why etcd Matters
| Fact | Detail |
| All cluster state lives in etcd | Pods, Services, ConfigMaps, Secrets, RBAC, everything |
| etcd uses Raft consensus | Guarantees consistency across nodes |
| etcd must have quorum | Majority of nodes must agree |
| etcd is the performance bottleneck | Slow etcd = slow cluster |
Raft Consensus and Quorum
etcd uses the Raft consensus algorithm. The core requirement is quorum: a majority of nodes must agree for a transaction to be committed.
The quorum formula:
text
Quorum = floor(N/2) + 1
3 nodes: quorum = 2, tolerates 1 failure
5 nodes: quorum = 3, tolerates 2 failures
7 nodes: quorum = 4, tolerates 3 failures
Why odd numbers? Even numbers don't improve fault tolerance. A 4-node cluster needs 3 nodes to confirm, but a 5-node cluster also needs only 3 nodes — yet the 5-node cluster can tolerate 2 failures versus 1 for the 4-node cluster.
Production recommendation: Use 3 nodes for most clusters, 5 for large-scale or high-availability-critical clusters. Never exceed 7 nodes — the performance overhead outweighs the fault tolerance benefit.
etcd Performance Requirements
| Requirement | Recommendation |
| Disk | SSD or NVMe with low fsync latency |
| Disk latency | < 10ms for fsync |
| Network | Low latency between etcd nodes (< 10ms) |
| Memory | Default 8 GB limit; monitor for quota issues |
| CPU | 2-4 dedicated cores |
The disk I/O warning: etcd's Raft messages (including heartbeats) must be persisted to the WAL log using fdatasync. If the underlying disk is a mechanical HDD, fsync latency can exceed 10ms, causing heartbeats to be delayed and triggering false leader elections.
etcd Heartbeat and Election Tuning
| Parameter | Default | Recommended (Cross-AZ) |
| heartbeat-interval | 100ms | 200ms |
| election-timeout | 1000ms | 1500ms+ |
The formula: election-timeout ≥ 5 × heartbeat-interval + max_network_rtt.
4. The Scheduler
kube-scheduler watches for unscheduled Pods (spec.nodeName is empty) and assigns each to a feasible Node.
The Filter → Score → Bind Pipeline
For every Pending Pod, the scheduler runs:
text
All Nodes
│
▼
PHASE 1: FILTERING
Drop nodes that can't fit the Pod
(resources, affinity, taints, ports)
│
▼
Feasible Nodes
│
▼
PHASE 2: SCORING
Score each feasible node (0-100)
(load balancing, spreading, locality)
│
▼
Highest-scoring node
│
▼
PHASE 3: BINDING
Write spec.nodeName onto the Pod
(via API server)
The scheduler only chooses and writes the node name onto the Pod. It doesn't start the container. Starting the container is the job of the kubelet on the chosen node.
The Scheduler Framework (Plugin Engine)
The scheduler is a plugin engine with ten extension points. Plugins register at different stages of the scheduling cycle.
| Extension Point | Purpose |
| QueueSort | Order Pods in the scheduling queue |
| PreFilter | Pre-process Pod info |
| Filter | Eliminate unsuitable nodes |
| PostFilter | Handle unschedulable Pods (preemption) |
| PreScore | Pre-process scoring |
| Score | Rank feasible nodes |
| Reserve | Reserve resources |
| Permit | Allow/deny/wait |
| PreBind | Pre-binding setup |
| Bind | Finalize placement |
The Default Scoring Strategy
The scheduler's default scoring strategy is LeastAllocated — it spreads workloads rather than packing them. This is intentional: it prioritizes failure-domain resilience over density.
Bin packing is opt-in via MostAllocated or RequestedToCapacityRatio in NodeResourcesFit.
The Critical Misunderstanding
The scheduler operates on requests, not actual usage. A Pod requesting 2 CPUs but using 200m looks like a 2-CPU Pod to every scoring and consolidation decision.
This is why right-sizing requests is critical for cluster efficiency.
5. The Controller Manager
kube-controller-manager is a single binary that bundles dozens of reconciliation loops.
The Controller Pattern
A controller is a continuous loop that:
- Observes the current state
- Compares it to the desired state
- Acts to reconcile the difference
text
Desired State (from API server)
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Controller Loop │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Observe │───►│ Compare │───►│ Act │ │
│ │ Current │ │ Desired vs │ │ (create, │ │
│ │ State │ │ Current │ │ update, │ │
│ └─────────────┘ └─────────────┘ │ delete) │ │
│ ▲ └──────┬──────┘ │
│ └──────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
What Controllers Run in kube-controller-manager
| Controller | What It Reconciles |
| Deployment | ReplicaSets for Deployments |
| ReplicaSet | Pods for ReplicaSets |
| Node | Node lifecycle, evictions |
| Job | Pods for Jobs |
| CronJob | Jobs on schedule |
| ServiceAccount | SA tokens |
| EndpointSlice | Service endpoints |
| Namespace | Namespace lifecycle |
| PersistentVolume | PV/PVC binding |
Special Roles
The controller-manager also:
- Signs CSRs (
--cluster-signing-cert-file,--cluster-signing-key-file) - Signs ServiceAccount tokens (
--service-account-private-key-file) - Knows the pod network range (
--cluster-cidr)
1:1 copy of the class Google Doc, code in code blocks.