Introduction to Kube Controller Manager

Reading Time: 4 minutes

In Kubernetes, there are five major component present in Control Plane. Let’s meet one of components that is kube-controller-manager.

kube controller manager : kube-controller-manager

It manages various controllers in Kubernetes. Controllers are control loops that continuously watch the state of your cluster, then make or request changes where needed. Each controller tries to move the current cluster state closer to the desired state.

Controllers continuously talk to the kube-apiserver and the kube-apiserver receives all information of nodes through Kubelet.


kube controller manager : Some types of controllers

1. Node Controller

It is responsible for onboarding new nodes to the cluster handling situations where nodes become unavailable or get destroyed to keep our application running.

If it stops receiving signals from a node, the node is marked unreachable but it waits for 40 seconds before marking it unreachable. After the node is marked unreachable it waits for 5 minutes to come back up if it doesn’t, it removes the POD’s assigned to that node and provisions them on the healthy nodes if PODs are part of the replica set.

2. Replica Controller

It is responsible for monitoring the status of replica sets and ensuring that the desired number of PODs are available at all times within the set. If a POD dies it will create another POD. It makes sure that desired number of PODs or at least one POD is in running state. It has the capability to bring up or down the specified no of PODs.

Example of a Replica-Controller

replicacontroller-definition.yml

apiVersion: v1
kind: ReplicaController
metadata:
  name: myapp-replicaset
  labels:
    app: myapp
    type: front-end
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
        - name: nginx-container
          image: nginx
  
  replicas: 3

To create the replica controller run the following command:

$ kubectl create -f replicacontroller-definition.yml

3. Job Controller

Watches for Job objects that represent one-off tasks then creates Pods to run those tasks to completion. When a new task comes, Job controller makes sure that in the cluster, the kubelets on nodes are running a good number of PODs to complete the work.

The job controller tells kube-apiserver to create or remove PODs and doesn’t run any PODs or containers by itself. So we have new information (there are new PODs to schedule and run) other components in control plane acts on this information to complete the work.

After you create a new Job, so in order to complete desired state for that Job. Job-controller creates PODs to do the work that you wanted for that Job so that current state for this Job be nearer to desired or closer to completion.

4. Deployment Controller

Deployments are managed by the Kubernetes Deployment controller. Deployments are set of multiple, identical Pods with no unique identities. A Deployment runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive. In this way, Deployments help ensure that one or more instances of your application are available to serve user requests.

Deployments use a Pod template, which contains a specification for its Pods. The Pod specification determines how each Pod should look like: what applications should run inside its containers, which volumes the Pods should mount, its labels, and more.

Deployment Controller manages functions like:

– Managing a set of pods in the form of Replica Sets & Hash-based labels
– Rolling out new versions of application through new Replica Sets
– Rolling back to old versions of application through old Replica Sets
– Pause & Resume Rollout/Rollback functions
– Scale-Up/Down functions

Example of a deployment.

nginx-deploy.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx-server
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-servers
        image: nginx:latest
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80

Execute and Run the deployment by running command in same directory:

$ kubectl create -f nginx-deploy.yaml

When all replicas of the application are ready and available to users output of our deployment look like:

Following command will show status of our deployments

$ kubectl get deployments

Output will look like:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
my-nginx-server    3/3     3            3           36s

References

Thanks for reading this blog. Checkout our website knoldus.com for engineering solutions and you can find more awesome blogs at https://blog.knoldus.com

Written by 

Rahul Soni is a Software Consultant at Knoldus Software. He is always charged up for new things & learnings. He is dedicated to his work and believes in quality output. He loves to take deep dives into cloud technologies & different tools.

1 thought on “Introduction to Kube Controller Manager4 min read

Comments are closed.