![]() |
VOOZH | about |
A Replication Controller (RC) is a Kubernetes controller that ensures a specified number of Pod replicas are running at all times. Just like a ReplicaSet, its core job is to monitor its managed Pods and automatically create or terminate them to match a desired count. This provides a basic level of fault tolerance and scaling.
The core responsibilities of a Replication Controller are:
replicas field in the RC's definition. Create a YAML file named rc-definition.yaml to define a Replication Controller.
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
spec:
replicas: 3
selector:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx
image: nginx
Explanation of the manifest:
apiVersion: v1: The Replication Controller is part of the core v1 API group.kind: ReplicationController: Defines the object type.metadata.name: The name of our Replication Controller.spec.replicas: 2: We desire 2 running Pods.spec.selector: This is the equality-based selector. It will manage any Pod with the label app: nginx-web.spec.template: The Pod template used to create new replicas. Its labels must match the selector.kubectl apply -f rc-definition.yamlkubectl get rc myapp-rc
# NAME DESIRED CURRENT READY AGE
# myapp-rc 3 3 3 15s
kubectl get pods
# NAME READY STATUS RESTARTS AGE
# myapp-rc-5j2x7 1/1 Running 0 25s
# myapp-rc-8b9vj 1/1 Running 0 25s
# myapp-rc-h4wz8 1/1 Running 0 25s
kubectl delete pod <one-of-your-pod-names>kubectl scale rc myapp-rc --replicas=5kubectl delete rc myapp-rcThe labels which are used in the replication controller are the key-value pairs that can be attached to the resources and can be reused for recognizing the resources. Labels play a major role in the replication controller where you can identify and organize the pods. By using labels you can also manage the scheduling of pods to the required nodes.
A pod selector will select the pods based on their labels. Pod selector works on the key/value pair where the selectors can be used in various Kubernetes resources like
selector:
app: nginx
multiple labels can be used in pod selector you can separate them by using commas as the following.
selector:
app: web app
tier: frontend
Repilcation Controller will make sure that the desired no.of pods that are created by using Replication Controller is matching.
Replication Controller | Replica Set |
|---|---|
ReplicationController will maintain the pod lifecycle by making sure that the desired is matching with no.of pods running. | Replicaset is the next-generation of replication controller. |
A Replication Controller is a structure that enables you to easily create multiple pods, then make sure that that number of pods always exists. | A Replicaset is a structure that enables you to easily create multiple pods, then make sure that that number of pods always exists. |
Replication Controllers and PODS are associated with labels | ReplicaSet and PODS are associated with the selectors. |
The major difference between a ReplicaSet and a Replication Controller right now is the selector support. | ReplicaSet supports the new set-based selector requirements as described in the labels user guide whereas a Replication Controller only supports equality-based selector requirements. |