Kubernetes: Controller Overview
What is Controller? Introduction to Kubernetes Controller
1. What is a Kubernetes Controller
A Kubernetes controller is a control loop that watches the state of your cluster, then makes changes to move the current cluster state closer to the desired state.
Here is a basic example of a control loop implementation:
desired := getDesiredState()
current := getCurrentState()
2. Desired State vs Current State
Almost every Kubernetes object includes two nested object fields that govern the object’s configuration: the object
spec and the object
spec describes the desired state of the object, providing a description of the characteristics you want the resource to have.
status describes the current state of the object, supplied and updated by the Kubernetes system and its components.
The Kubernetes Controllers continually and actively manages every object's current state to match the desired state you supplied.
3. Controller Pattern
Controller pattern is a pattern that actively monitors and maintains a set of Kubernetes resources in a desired state.
The heart of Kubernetes itself consists of a fleet of controllers that regularly watch and reconcile the current state of applications with the desired state.
This pattern describes how to leverage this core concept for extending the platform for our own applications.
4. Kubernetes Built-in Controllers
A large number of Kubernetes Controllers run in two major components in Control Plane, kube-controller-manager and cloud-controller-manager.
Logically, each controller is a separate process, but to reduce complexity, they are all compiled into a single binary and run in a single process.
Some types of these controllers are:
- Node controller: Responsible for noticing and responding when nodes go down.
- Job controller: Watches for Job objects that represent one-off tasks, then creates Pods to run those tasks to completion.
- Endpoints controller: Populates the Endpoints object (that is, joins Services & Pods).
- Service Account & Token controllers: Create default accounts and API access tokens for new namespaces.
The cloud-controller-manager only runs controllers that are specific to your cloud provider, and lets you link your cluster into your cloud provider’s API.
The cloud-controller-manager also combines various controllers into a single binary that you run as a single process. You can scale horizontally (run more than one copy) to improve performance or to help tolerate failures.
The following controllers can have cloud provider dependencies:
- Node controller: For checking the cloud provider to determine if a node has been deleted in the cloud after it stops responding
- Route controller: For setting up routes in the underlying cloud infrastructure
- Service controller: For creating, updating and deleting cloud provider load balancer
For More details, see https://kubernetes.io/docs/concepts/architecture/controller/