Kubernetes: Controller Overview

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.

Control Loop

Here is a basic example of a control loop implementation:

for {
desired := getDesiredState()
current := getCurrentState()
makeChanges(desired, current)
}

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 status.

The spec describes the desired state of the object, providing a description of the characteristics you want the resource to have.

The 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.

The components of a Kubernetes cluster

kube-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.

kube-controller-manager: multiple controllers in one binary

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.

cloud-controller-manager

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Able Lv

Able Lv

Cloud Infrastructure Engineer @Airwallex: Kubernetes, DevOps, Terraform, Istio, Go, and Cloud-Native stuff