Replication Controller

A Replication Controller is a Kubernetes abstraction that ensures that a specific number of pods are running at all times. If a pod or host goes down, the replication controller ensures enough pods get recreated elsewhere.

A pod template is used to define what each pod should look like (e.g. the docker container image to use, its ports and environment variables, etc).

The containers generated can have labels so that containers can be filtered to create services.

Link between Replica controller and Pod

How does Replica Controller know which Pod to manage? It happens via a keyword label and selectors.

In the Replica Controller, we define selectors which basically points to the label defined in Pod.

Create a file replicationController.yml

apiVersion: v1
kind: ReplicationController
  name: rcontroller-nginx
  replicas: 3
    app: my-nginx-app
      name: nginx-pod
        app: my-nginx-app
        - name: nginx-container
          image: coolgourav147/nginx-custom

Now deploy the above RC using

kubectl apply -f replicationController.yml

check our pods using

kubectl get pods

Let's delete one pod and check if any new pods get created.

kubectl delete pod <podname>

You might be seeing one new Pod being created.

get the replication controller using below command

kubectl get rc

Describe the ReplicationController:

kubectl describe rc nginx-rc

To scale up the replicas:

kubectl scale rc nginx-rc --replicas=5

To delete the ReplicationController:

kubectl delete rc nginx-rc
kubectl delete -f replicationController.yml