In the previous posts we’ve seen Introduction to Kubernetes Pods and Deploy your first Pod in Kubernetes, In this post we will be seeing, What is Replication Controller in Kubernetes.
So let’s get started!!
What is Replication Controller?
Replication Controller make sure that at least n number of pods are running in our Kubernetes cluster, where n is the number of of replicas we define.
So Replication Controller maintains the desired number of Pods always.
Link between RC and Pod
How does RCA knows which Pod to manage? – It happens via a keyword label and selectors.
In the RC we define selectors which basically points to the label defined in Pod.
So let’s write manifest.yml
Create a file replicationController.yml
apiVersion: v1 kind: ReplicationController metadata: name: rcontroller-nginx spec: replicas: 3 selector: app: my-nginx-app template: metadata: name: nginx-pod labels: app: my-nginx-app spec: containers: - name: nginx-container image: nginx
Now deploy the above RC using
kubectl apply -f replicationController.yml
let’s check our pods using
kubectl get pods to verify the same!!
Now let’s say we want to scale our pods from 3 to 5
kubectl scale rc rcontroller-nginx --replicas 5
Verify the 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 and it’s been 7 seconds it’s up.
This all how you can get started with Replication Controller, do post queries in comment section if you have one.!!!!