Kubernetes Architecture
Understanding Kubernetes architecture is essential for effectively using, troubleshooting, and operating Kubernetes clusters. The architecture determines how Kubernetes makes decisions, stores state, schedules workloads, and maintains desired configurations.
Kubernetes follows a distributed systems architecture with clear separation between the control plane (decision-making) and data plane (execution). Think of it like a company: the control plane is management making decisions and coordinating work, while the data plane (worker nodes) is the workforce executing those decisions.
Architecture Overview
Kubernetes clusters consist of two main parts:
Control Plane - Makes global decisions about the cluster (scheduling, responding to events) and maintains the desired state of the cluster.
Worker Nodes - Run the containerized applications. Each node can run multiple pods.
Control Plane vs Data Plane
Control Plane (Master Components)
The control plane is the “brain” of Kubernetes. It’s responsible for:
- Making decisions - Where to schedule pods, how to respond to failures
- Maintaining state - Storing cluster configuration and current state
- Exposing API - Providing the interface for all cluster interactions
- Watching and reconciling - Ensuring actual state matches desired state
Control plane components can run on dedicated machines or be co-located on the same machines. For production, they’re typically distributed across multiple machines for high availability.
Data Plane (Worker Nodes)
The data plane is where your applications actually run. It consists of:
- Worker nodes - Machines that run containerized applications
- Kubelet - Agent that communicates with the control plane
- Container runtime - Software that runs containers (containerd, CRI-O)
- kube-proxy - Network proxy that maintains network rules
The data plane executes the decisions made by the control plane.
Control Plane Components
The control plane consists of several components that work together:
API Server
The API server is the front end of the Kubernetes control plane. It’s the only component that directly communicates with etcd and exposes the Kubernetes API. All other components and users interact with Kubernetes through the API server.
Responsibilities:
- Validates and processes API requests
- Authenticates and authorizes requests
- Reads from and writes to etcd
- Serves the Kubernetes API
etcd
etcd is a distributed, consistent key-value store used as Kubernetes’ backing store for all cluster data. It’s the “memory” of Kubernetes—everything the cluster knows is stored here.
Responsibilities:
- Stores cluster state (pods, services, deployments, etc.)
- Provides watch functionality for change notifications
- Ensures consistency across the cluster
Scheduler
The scheduler watches for newly created pods with no assigned node and selects a node for them to run on.
Responsibilities:
- Watches for unscheduled pods
- Evaluates node resources, constraints, and policies
- Assigns pods to nodes
- Considers resource requests, affinity rules, taints, and tolerations
Controller Manager
The controller manager runs controllers that watch the cluster state and make changes to move the current state toward the desired state.
Responsibilities:
- Runs controllers (Deployment, ReplicaSet, Service, etc.)
- Watches for changes in cluster state
- Takes corrective action to achieve desired state
- Handles node failures, pod failures, and other events
Cloud Controller Manager (Optional)
In cloud environments, the cloud controller manager integrates Kubernetes with cloud provider APIs for load balancers, storage, and networking.
Worker Node Components
Each worker node runs several components:
Kubelet
The kubelet is an agent that runs on each node and ensures containers are running in pods.
Responsibilities:
- Registers the node with the API server
- Watches for pod assignments
- Starts and stops containers via the container runtime
- Reports node and pod status to the API server
- Runs liveness and readiness probes
Container Runtime
The container runtime is the software responsible for running containers. Kubernetes supports any runtime that implements the Container Runtime Interface (CRI), such as containerd or CRI-O.
Responsibilities:
- Pulling container images
- Starting and stopping containers
- Managing container lifecycle
- Providing container isolation
kube-proxy
kube-proxy is a network proxy that runs on each node and maintains network rules that allow communication to pods.
Responsibilities:
- Implementing Service abstraction
- Load balancing traffic to pods
- Maintaining iptables or IPVS rules
- Handling service discovery
Component Communication
Components communicate through well-defined patterns:
API Server as Central Hub
The API server is the central communication hub. All components communicate through it:
- Components watch the API server for changes
- Components update the API server with status
- The API server validates and stores everything in etcd
Watch Pattern
Kubernetes uses a watch pattern for efficient change notification:
- Components watch for changes to resources
- The API server streams changes as they occur
- Components react to changes immediately
This is more efficient than polling and ensures components stay in sync.
How Components Work Together
Pod Creation Flow
- User creates pod - Sends request to API server
- API server validates - Checks request and stores in etcd
- Scheduler watches - Detects unscheduled pod
- Scheduler assigns - Selects node and updates pod
- Kubelet watches - Detects pod assignment to its node
- Kubelet creates - Instructs container runtime to create container
- Status updates - Kubelet reports status back to API server
Self-Healing Flow
- Pod fails - Container crashes or node fails
- Kubelet detects - Reports status to API server
- Controller watches - Deployment controller detects mismatch
- Controller reconciles - Creates new pod to replace failed one
- Scheduler assigns - New pod scheduled to available node
- Kubelet creates - New container starts
High Availability Architecture
For production clusters, the control plane should be highly available:
- Multiple API servers - Behind a load balancer for redundancy
- etcd cluster - Typically 3 or 5 nodes for quorum
- Multiple schedulers - Leader election ensures only one active scheduler
- Multiple controller managers - Leader election ensures only one active controller manager
Topics
- Control Plane Components - Deep dive into control plane components
- Node & Kubelet - Understanding worker nodes and the kubelet
- etcd Basics - Kubernetes’ backing store
Key Takeaways
- Kubernetes has a clear separation between control plane (decisions) and data plane (execution)
- The API server is the central hub for all communication
- etcd stores all cluster state
- The scheduler assigns pods to nodes
- Controllers maintain desired state
- Worker nodes run your applications via kubelet and container runtime
- Components use watch patterns for efficient change notification
- High availability requires multiple control plane nodes and etcd cluster
See Also
- Basics of Kubernetes - Core Kubernetes concepts
- APIs & Access - How to interact with the API
- High Availability Overview - Making clusters resilient
- Cluster Operations - Managing Kubernetes clusters