A replication controller ensures that a specified number of replicas of a pod
are running at all times. If pods exit or are deleted, the replica controller
acts to instantiate more up to the desired number. Likewise, if there are more
running than desired, it deletes as many as necessary to match the number.
The definition of a replication controller consists mainly of:
-
The number of replicas desired (which can be adjusted at runtime).
-
A pod definition for creating a replicated pod.
-
A selector for identifying managed pods.
The selector is just a set of labels that all of the pods managed by the
replication controller should have. So that set of labels is included
in the pod definition that the replication controller instantiates.
This selector is used by the replication controller to determine how many
instances of the pod are already running in order to adjust as needed.
It is not the job of the replication controller to perform auto-scaling
based on load or traffic, as it does not track either; rather, this
would require its replica count to be adjusted by an external auto-scaler.
Replication controllers are a core Kubernetes object, ReplicationController
.
The
Kubernetes documentation
has more details on replication controllers.
Here is an example ReplicationController
definition with some omissions and callouts:
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend-1
spec:
replicas: 1 (1)
selector: (2)
name: frontend
template: (3)
metadata:
labels: (4)
name: frontend (5)
spec:
containers:
- image: openshift/hello-openshift
name: helloworld
ports:
- containerPort: 8080
protocol: TCP
restartPolicy: Always
-
The number of copies of the pod to run.
-
The label selector of the pod to run.
-
A template for the pod the controller creates.
-
Labels on the pod should include those from the label selector.
-
The maximum name length after expanding any parameters is 63 characters.