What is ReplicationController in Kubernetes?
Replication Controller ensure that number of specified replicas run at a time.
ReplicationControllr control POD make sure desired number of PODs always be ready for service request.
If there are too many pods, the ReplicationController terminates the extra pods.
If there are too few, the ReplicationController starts more pods.
Unlike manually created pods, the pods maintained by a ReplicationController are automatically replaced if they fail, are deleted, or are terminated.
Behavior:
Keeps POD running
Gives Direct Control of PODs.
Benefits:
Restart PODs , Desired State.
Fine grained control for scaling..
In above diagram we can see replication controller with pod count 2 and selector v1 keeps 2 PODs up.
and in second diagram we can see RC keep one POD always up.
When a node fails, only pods backed by a replication controller are recreated.
In above diagram we can see POD1 dies with node-1. POD2 created new replica on node2
Create Replication Controller:
Execute below command:
kubectl apply -f https://k8s.io/examples/controllers/replication.yaml
The output is similar to this:
replicationcontroller/nginx created
Replication Controller Yaml File:
root@ip-172-31-31-126:~# kubectl describe replicationcontrollers/nginx
Delete Replication Controller:
root@ip-172-31-31-126:~# kubectl get rc ==> Display available ReplicationController
NAME DESIRED CURRENT READY AGE
nginx 3 3 3 33m
root@ip-172-31-31-126:~# kubectl delete rc nginx ==> It will delete RC nginx.
replicationcontroller "nginx" deleted
Scale Up:
root@ip-172-31-31-126:~# kubectl scale rc --replicas=7 nginx
replicationcontroller/nginx scaled
root@ip-172-31-31-126:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-7pbtj 1/1 Running 0 10s
nginx-f247s 1/1 Running 0 10s
nginx-lj2ln 1/1 Running 0 2m31s
nginx-ptv2j 1/1 Running 0 2m31s
nginx-pzjq8 1/1 Running 0 10s
nginx-skltf 1/1 Running 0 10s
nginx-xm262 1/1 Running 0 2m31s
root@ip-172-31-31-126:~# kubectl get rc
NAME DESIRED CURRENT READY AGE
nginx 7 7 7 2m37s
root@ip-172-31-31-126:~#
Scale Down:
root@ip-172-31-31-126:~# kubectl scale rc --replicas=3 nginx
replicationcontroller/nginx scaled
root@ip-172-31-31-126:~# kubectl get rc
NAME DESIRED CURRENT READY AGE
nginx 3 3 3 3m33s
root@ip-172-31-31-126:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-lj2ln 1/1 Running 0 3m39s
nginx-ptv2j 1/1 Running 0 3m39s
nginx-xm262 1/1 Running 0 3m39s
Another option we can change yml file
No comments:
Post a Comment