Skip to main content

Chapter 2.4 - Controller Manager

Learning Objectives​

By the end of this chapter, you will be able to:

  • Understand the role of the Controller Manager
  • Explain the control loop pattern
  • Identify the different controllers
  • Understand how Kubernetes maintains the desired state

What is the Controller Manager?​

The Controller Manager (kube-controller-manager) runs the controllers that monitor the cluster state and take actions to make the actual state match the desired state.


Control Loop Pattern​

Controllers follow a control loop pattern:

Characteristics:

  • Continuous monitoring (watch)
  • Comparison of actual vs desired state
  • Automatic corrective actions
  • Reconciliation loop

Main Controllers​

1. Deployment Controller​

Manages Deployments and maintains the number of replicas:

Actions:

  • Creates ReplicaSets
  • Manages Rolling Updates
  • Performs Rollbacks

2. ReplicaSet Controller​

Maintains the desired number of Pods:

3. Node Controller​

Monitors node status:

  • Detects unavailable nodes
  • Marks nodes as NotReady
  • Prevents scheduling Pods on failing nodes

4. Service Controller​

Manages Services and their endpoints:

  • Creates/maintains Endpoints
  • Synchronizes with cloud LoadBalancers

5. Job Controller​

Manages Jobs and CronJobs:

  • Monitors Job execution
  • Manages CronJobs (scheduled tasks)

Concrete Example: Deployment​

Initial Scenario​

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
template:
spec:
containers:
- name: app
image: nginx:1.20

What happens:​

  1. Deployment Controller reads the Deployment
  2. Creates a ReplicaSet with 3 replicas
  3. ReplicaSet Controller verifies there are 3 Pods
  4. If a Pod crashes, the ReplicaSet Controller creates a new Pod
  5. The Scheduler assigns the new Pod to a node
  6. The kubelet starts the container

Reconciliation (Reconciliation Loop)​

Concept​

Reconciliation is the continuous process of:

  1. Observing the current state
  2. Comparing with the desired state
  3. Taking actions to reduce the gap

Example: ReplicaSet​


Performance and Optimizations​

Rate Limiting​

Controllers limit the number of requests to avoid overloading the API Server.

Backoff​

On error, controllers wait before retrying (exponential backoff).

Concurrent Workers​

Multiple workers process resources in parallel.


Useful Commands​

# View Controller Manager logs
kubectl logs -n kube-system kube-controller-manager-<node>

# View controller-related events
kubectl get events --sort-by='.lastTimestamp'

# Check Deployment status
kubectl describe deployment <name>

Summary​

In this chapter, you learned:

Controller Manager: Runs controllers that maintain the desired state
Control pattern: Continuous monitoring, comparison, corrective action
Main controllers: Deployment, ReplicaSet, Node, Service, Job
Reconciliation: Continuous process of maintaining the desired state
Self-healing: Controllers automatically correct deviations


Next Steps​

Now that you understand the Controller Manager:

Chapter 2.5: Scheduler - Pod Scheduling
Chapter 2.6: kubelet - Worker Node Agent


Chapter created: December 2024