The Kubernetes Control Plane is the "brain" of the cluster, responsible for managing and controlling the state of the entire cluster. It consists of multiple components, each with specific responsibilities.
Control Plane Components
1. API Server (kube-apiserver)
The API Server is the core component of the Kubernetes Control Plane and the unified entry point for the cluster.
Main Responsibilities:
- Provides REST API interfaces for users, other components, and external systems to call
- Validates and configures data for API objects (such as Pod, Service, Deployment)
- Handles authentication, authorization, and admission control
- Acts as the only client for etcd, all data reads and writes go through the API Server
Features:
- Stateless design, can be horizontally scaled
- Listens on port 6443 (HTTPS) by default
- Supports Swagger/OpenAPI documentation
2. etcd
etcd is the distributed key-value storage for Kubernetes, used to store all configuration and state data of the cluster.
Main Responsibilities:
- Stores cluster state data
- Provides data consistency and reliability guarantees
- Supports distributed deployment and fault recovery
Features:
- Based on Raft consistency algorithm
- Supports transactions and Watch mechanism
- Uses ports 2379 (client) and 2380 (cluster communication) by default
Best Practices:
- Regularly backup etcd data
- Use TLS for encrypted communication
- Configure reasonable resource limits
3. Scheduler (kube-scheduler)
The Scheduler is responsible for assigning newly created Pods to suitable Nodes to run.
Main Responsibilities:
- Monitors unscheduled Pods
- Selects the optimal Node based on scheduling policies
- Writes scheduling results to the API Server
Scheduling Process:
- Filtering (Predicates): Excludes Nodes that do not meet the conditions
- Scoring (Priorities): Scores Nodes that meet the conditions
- Selection: Selects the Node with the highest score
Scheduling Policies:
- Resource requests and limits
- Node selectors (nodeSelector)
- Affinity and anti-affinity
- Taints and tolerations
- Node resource utilization
4. Controller Manager (kube-controller-manager)
The Controller Manager runs multiple controllers that are responsible for maintaining the desired state of the cluster.
Main Controllers:
-
Node Controller:
- Monitors Node status
- Marks Nodes as NotReady when they are unavailable
- Evicts Pods when Nodes fail
-
Replication Controller:
- Ensures that the number of Pod replicas matches the desired value
- Creates or deletes Pods to maintain the replica count
-
Endpoints Controller:
- Maintains the correspondence between Services and Pods
- Updates Endpoint objects
-
Service Account & Token Controller:
- Creates default ServiceAccount for new Namespaces
- Manages API access tokens
-
Deployment Controller:
- Manages rolling updates for Deployments
- Creates and updates ReplicaSets
-
StatefulSet Controller:
- Manages the Pod lifecycle for StatefulSets
- Maintains stable Pod identities
-
DaemonSet Controller:
- Ensures that one Pod replica runs on each Node
-
Job Controller:
- Manages one-time tasks
- Ensures that tasks complete successfully
-
CronJob Controller:
- Manages scheduled tasks
- Creates Jobs based on schedules
Features:
- Each controller runs independently
- Uses the Watch mechanism to monitor resource changes
- Updates resource status through the API Server
5. Cloud Controller Manager (cloud-controller-manager)
The Cloud Controller Manager is a cloud provider-specific controller used to integrate Kubernetes with cloud platforms.
Main Responsibilities:
- Manages the lifecycle of cloud provider Nodes
- Manages cloud routing
- Manages cloud storage volumes
- Manages service load balancers
Advantages:
- Separates cloud-related logic from the Kubernetes core
- Improves code maintainability
- Facilitates support for multiple cloud providers
Control Plane Workflow
-
User Request: Users send requests to the API Server through kubectl or API
-
Authentication and Authorization: The API Server verifies user identity and permissions
-
Data Storage: The API Server writes data to etcd
-
Controller Monitoring: Each controller monitors resource changes through the Watch mechanism
-
State Coordination: Controllers coordinate the actual state based on the desired state
-
Scheduling Decision: The Scheduler selects a Node for unscheduled Pods
-
State Update: Controllers and the Scheduler write update results back to the API Server
High Availability Deployment
To improve the availability of the control plane, it is recommended to:
-
API Server: Deploy multiple instances and use a load balancer
-
etcd: Deploy an odd number of nodes (3, 5, 7), using stacked or external etcd topology
-
Scheduler and Controller Manager: Deploy multiple instances and use leader election
Monitoring and Debugging
- Check component status:
bashkubectl get componentstatuses
- View Pod logs:
bashkubectl logs -n kube-system kube-apiserver-xxx
- View events:
bashkubectl get events -n kube-system
Best Practices
-
Resource Limits: Set reasonable CPU and memory limits for control plane components
-
Security Hardening:
- Enable RBAC
- Use TLS for encrypted communication
- Limit API Server access
-
Backup Strategy: Regularly backup etcd data
-
Monitoring and Alerting: Monitor the health status of control plane components
-
Version Upgrade: Follow the Kubernetes version upgrade strategy and upgrade gradually
-
Log Management: Centrally collect and analyze control plane logs