Kubernetes Cluster Architecture
What is a Kubernetes Cluster?
A Kubernetes cluster is a set of machines (physical or virtual) that work together to run containerized applications. The cluster provides a unified platform for deploying, scaling, and managing applications.
Cluster Components
A Kubernetes cluster consists of two main types of components:
- Control Plane (Master) Components: Manage the overall state of the cluster
- Node (Worker) Components: Run the actual application workloads
High-Level Architecture
Kubernetes Cluster Architecture
- API Server - Central entry point
- etcd - Distributed key-value store
- Scheduler - Pod placement decisions
- Controller Manager - Maintains desired state
Commands & State Management
⬇
- Kubelet - Node agent
- Container Runtime - Runs containers (Docker, containerd)
- Kube-proxy - Network proxy
- Pods - Running applications
Critical Understanding
Cluster Dependencies
Important: A cluster cannot function without its core components. If critical components like the API Server or etcd fail, the cluster loses its ability to manage workloads.
Control Plane vs. Worker Nodes
| Aspect | Control Plane | Worker Nodes |
|---|---|---|
| Purpose | Manage and control the cluster | Run application workloads |
| Responsibilities | Scheduling, scaling, monitoring, updates | Execute containers and maintain Pods |
| Key Components | API Server, etcd, Scheduler, Controllers | Kubelet, Container Runtime, Kube-proxy |
| Typical Count | 1-3 (HA setup) | Many (scales with workload) |
| Runs User Apps | No (usually) | Yes |
Communication Flow
Creates resource (e.g., kubectl create deployment)
Receives request, validates, authenticates
Stores desired state
Detects new Deployment, creates ReplicaSet
Selects appropriate node for Pod
Receives instruction, starts containers
Actually runs the container
Cluster Characteristics
High Availability
Production clusters typically run multiple Control Plane nodes for redundancy:
- 3+ Control Plane nodes (odd number for quorum)
- etcd distributed across multiple nodes
- Load balancer in front of API Servers
- Multiple worker nodes for application redundancy
Scalability
Kubernetes clusters can scale to support:
- Up to 5,000 nodes
- Up to 150,000 Pods
- Up to 300,000 containers
Key Takeaways
- Cluster = Control Plane + Worker Nodes
- Control Plane manages, Workers execute
- All components are essential for cluster operation
- Communication flows through the API Server
- etcd stores all cluster state
Control Plane Components
The Control Plane
The Control Plane (also called Master components) is the brain of the Kubernetes cluster. It makes global decisions about the cluster and detects and responds to cluster events.
Control Plane Responsibilities
- Accept and validate user requests
- Store cluster state
- Schedule Pods to nodes
- Monitor cluster health
- Maintain desired state
1. API Server (kube-apiserver)
The API Server is the central entry point and the heart of Kubernetes. It exposes the Kubernetes API and serves as the frontend for the Control Plane.
API Server Role
The API Server is the only component that directly communicates with etcd. All other components interact with the cluster state through the API Server.
Key Functions
- Central communication hub: All internal component communication goes through it
- External interface: All user requests (kubectl commands) are sent to it
- Authentication & Authorization: Validates who can access the cluster and what they can do
- Admission Control: Validates and potentially modifies requests
- REST API: Provides HTTP REST interface for cluster operations
API Server Communication
2. etcd
etcd is a highly available, distributed key-value store that serves as Kubernetes' backing store for all cluster data.
Single Source of Truth
etcd is the single source of truth for the entire cluster. Everything Kubernetes knows is stored in etcd.
What etcd Stores
- Cluster configuration: Settings and parameters
- Desired state: All resource manifests (Deployments, Services, etc.)
- Current state: Which Pods are running, on which nodes
- Secrets and ConfigMaps: Configuration data
- Network policies, RBAC rules: Security configurations
- Node information: Available nodes and their status
etcd Characteristics
- Distributed: Runs on multiple nodes for redundancy
- Consistent: Uses Raft consensus algorithm
- Fast: Optimized for read and write operations
- Secure: Supports TLS and authentication
Critical Component
If etcd fails, the cluster loses its memory. Always back up etcd in production!
- Without etcd, the API Server can't function
- Without etcd, you lose all cluster configuration
- Regular backups are essential
3. Scheduler (kube-scheduler)
The Scheduler is responsible for selecting a suitable node for newly created Pods that don't yet have a node assignment.
Scheduling Process
Scheduler monitors API Server for Pods with no node assigned
Eliminate nodes that don't meet requirements (resources, taints, affinity)
Rank remaining nodes based on factors (available resources, spread, etc.)
Assign Pod to highest-scoring node
Write the scheduling decision to etcd
Scheduling Factors
- Resource requests: Does node have enough CPU/memory?
- Node selectors: Does Pod require specific node labels?
- Affinity/Anti-affinity: Should Pod be near or away from others?
- Taints and tolerations: Can Pod tolerate node taints?
- Resource balance: Spread load evenly across nodes
4. Controller Manager (kube-controller-manager)
The Controller Manager runs multiple controllers that continuously monitor the cluster state and work to maintain the desired state.
What Controllers Do
Controller Loop (Reconciliation)
- Watch the API Server for changes
- Compare current state vs. desired state
- Take action to reconcile the difference
- Repeat continuously
Key Controllers
- Node Controller: Monitors node health, marks unhealthy nodes
- Replication Controller: Ensures correct number of Pod replicas
- Endpoints Controller: Populates Endpoints objects (connects Services to Pods)
- Service Account Controller: Creates default service accounts for namespaces
- Deployment Controller: Manages Deployments and ReplicaSets
- Job Controller: Manages one-off tasks
Controllers Work Together
Control Plane Summary
- API Server: Central hub for all communication
- etcd: Single source of truth, stores all state
- Scheduler: Decides where Pods should run
- Controller Manager: Maintains desired state through controllers
All these components work together to manage the cluster!
Node (Worker) Components
Worker Nodes
Worker nodes are the machines where your actual application containers run. Each node contains the services necessary to run Pods and is managed by the Control Plane.
Node Responsibilities
- Run application containers
- Monitor Pod health
- Report status to Control Plane
- Provide networking for Pods
- Manage local resources
1. Kubelet
The Kubelet is the essential node agent that must run on every worker server in the cluster.
Critical Component
The Kubelet is the most important component on a node. Without it, the node cannot participate in the cluster.
Kubelet Responsibilities
- Pod lifecycle management: Starts, stops, and monitors containers
- Listens to API Server: Watches for Pod assignments to its node
- Container runtime interface: Talks to Docker/containerd to run containers
- Health checking: Runs liveness and readiness probes
- Resource monitoring: Reports node and Pod resource usage
- Volume management: Mounts volumes into containers
How Kubelet Works
Kubelet continuously watches for Pods assigned to its node
Gets Pod definition from API Server
Instructs runtime (Docker/containerd) to pull images
Container runtime creates and starts containers
Continuously runs health probes
Updates Pod status in API Server
Kubelet Configuration
Kubelet Independence
The Kubelet can run Pods even if the Control Plane is unavailable (for Pods already scheduled). However, no new Pods can be scheduled without the Control Plane.
2. Container Runtime
The Container Runtime is the software responsible for actually running containers on the node.
Supported Runtimes
- containerd: Industry standard, lightweight (recommended)
- CRI-O: Lightweight alternative designed for Kubernetes
- Docker: Popular but deprecated in favor of containerd
Container Runtime Interface (CRI)
Kubernetes uses the CRI to communicate with different container runtimes in a standardized way. This allows Kubernetes to work with any CRI-compatible runtime.
3. Kube-proxy
The kube-proxy is a network proxy that runs on each node and maintains network rules for Pod communication.
Kube-proxy Functions
- Service abstraction: Implements Kubernetes Services
- Load balancing: Distributes traffic across Pod replicas
- Network rules: Configures iptables or IPVS rules
- Service discovery: Routes traffic to correct Pods
Kube-proxy Modes
- iptables (default): Uses iptables rules for routing
- IPVS: More efficient for large clusters
- userspace: Legacy mode, not recommended
Additional Node Components
CNI (Container Network Interface) Plugin
Provides Pod networking capabilities:
- Assigns IP addresses to Pods
- Sets up network routes
- Enables Pod-to-Pod communication
- Examples: Calico, Flannel, Weave
CSI (Container Storage Interface) Plugin
Provides persistent storage:
- Mounts volumes to Pods
- Manages storage lifecycle
- Examples: AWS EBS, GCE PD, NFS
Node Architecture Visualization
Worker Node Components
Manages Pod lifecycle, reports to API Server
Pulls images and runs containers
Manages network rules for Services
Running containers with your code
Node Components Summary
- Kubelet: Essential node agent, manages Pods
- Container Runtime: Actually runs containers
- Kube-proxy: Handles networking and Services
- All three must be running for a node to function
How Components Work Together
Complete Workflow: Creating a Deployment
Let's see how all components collaborate when you create a Deployment:
Developer runs: kubectl create deployment nginx --image=nginx --replicas=3
• Authenticates and authorizes request
• Validates Deployment spec
• Writes Deployment object to etcd
• Watches API Server, detects new Deployment
• Creates ReplicaSet for the Deployment
• Writes ReplicaSet to API Server → etcd
• Detects new ReplicaSet
• Sees desired count: 3 replicas
• Creates 3 Pod objects
• Writes Pods to API Server → etcd
• Detects 3 unscheduled Pods
• Evaluates all nodes
• Assigns each Pod to a suitable node
• Updates Pod specs with node assignment
• Detects Pod assigned to its node
• Tells container runtime to pull nginx image
• Instructs runtime to start container
• Reports Pod status to API Server
• Pulls nginx image from registry
• Creates container from image
• Starts container process
• Container now running!
• Kubelet runs health probes
• Controllers monitor for drift
• System maintains desired state
Component Interactions
Maintaining Desired State
Controllers continuously work to maintain the desired state:
Watch Mechanism
Components use a "watch" mechanism to stay informed:
How Watch Works
- Component opens a watch connection to API Server
- API Server sends immediate notification when relevant resources change
- Component reacts to changes in real-time
- No polling needed - very efficient
Failure Scenarios
Scenario 1: API Server Fails
Impact: Cluster Management Stops
- Existing workloads: Continue running (Kubelet keeps them alive)
- New operations: Impossible (can't create/update/delete resources)
- Monitoring: No status updates
- Self-healing: Stopped (controllers can't work)
Scenario 2: etcd Fails
Impact: Cluster Loses Memory
- Existing workloads: Continue running
- State loss: Cluster forgets all configuration
- API Server: Can't serve requests (no data source)
- Recovery: Must restore from backup
Scenario 3: Kubelet Fails on a Node
Impact: Node Becomes Unmanageable
- Existing Pods: May continue running (depends on container runtime)
- New Pods: Can't be started on that node
- Health checks: Stop working
- Status updates: Node marked as NotReady
High Availability Setup
Production clusters use HA configuration:
Key Principles
- All communication goes through API Server
- Only API Server writes to etcd
- Controllers use watch for real-time updates
- System continuously reconciles actual vs desired state
- HA setup prevents single points of failure
Kubernetes in Practice: CI/CD & Helm
Kubernetes for Development
Kubernetes provides a convenient platform for both development and production deployments, with features that integrate well with modern CI/CD workflows.
Development Benefits
- Environment parity: Dev/staging/prod all use Kubernetes
- Easy testing: Quick to spin up isolated environments
- Declarative config: Infrastructure as code
- API-driven: Easy to automate
Automated Rollouts with CI/CD
CI/CD tools can monitor the API Server to track deployment status and automatically handle failures.
Typical CI/CD Workflow
Developer pushes code to Git repository
CI system builds container image, pushes to registry
CI tool updates Deployment with new image tag
CI tool watches API Server for rollout status
Check if new Pods are running and passing health checks
If healthy: deployment complete
If unhealthy: automatic rollback
Automatic Rollbacks
CI/CD tools can monitor deployment health and automatically rollback on failure:
How CI/CD Monitors via API Server
Rollback Benefits
- Prevents bad deployments from staying in production
- Reduces downtime from failed deployments
- Provides safety net for developers
- Ensures project fault tolerance
Introduction to Helm
Helm is the package manager for Kubernetes. It simplifies deploying and managing complex applications.
What is Helm?
Helm packages Kubernetes resources into Charts - reusable, versioned bundles that can be easily shared and deployed.
Why Use Helm?
- Templating: Parameterize YAML files for different environments
- Package management: Install complex apps with one command
- Versioning: Track and rollback releases
- Sharing: Distribute applications via Helm repositories
- Dependencies: Manage related applications together
Helm Concepts
Helm Example
Without Helm
With Helm
Creating a Custom Helm Chart
Basic chart structure:
Helm Commands
Future Learning
The course will cover:
- Detailed Helm explanation
- Creating custom charts
- Hands-on exercises deploying applications
- Chart best practices
- Managing dependencies
Production Best Practices
Kubernetes in Production
- Use CI/CD: Automate deployments and rollbacks
- Monitor rollouts: Watch API Server for deployment status
- Implement health checks: Enable automatic detection of failures
- Use Helm: Simplify complex deployments
- Version everything: Container images, Helm charts, configs
- Test rollbacks: Ensure you can recover from failures
- HA Control Plane: Prevent single points of failure
- Backup etcd: Regularly backup cluster state
Summary: Kubernetes Architecture
Complete Kubernetes Architecture
- API Server - Central hub
- etcd - Source of truth
- Scheduler - Pod placement
- Controller Manager - Maintain desired state
- Kubelet - Node agent
- Container Runtime - Run containers
- Kube-proxy - Networking
- Pods - Your applications
- CI/CD - Automated deployments
- Helm - Package management
- kubectl - Command-line interface