Replication controllers

At first sight, one may think that we should care about pods, but Kubernetes recommends using another abstraction called replication controllers.

You will never run one pod instance in production. Instead, you will run many of them to offer high availability and to support all the traffic. Replication controllers are intended to ensure that a specified number of pods are up and running. It's common to have issues with services running in the wild, and sometimes a host crashes, making one or more pods unavailable. Replication controllers are constantly monitoring the system for such problems, and when a pod crashes, it automatically creates a new replica for this pod, as shown in the following diagram:

Replica services and pods
Replica controllers are also useful for rolling out new application versions. You can easily turn off all the pods associated with a specific replica and then turn the new one on. 

Let's review the following file, which shows an example of a replication controller:

apiVersion: v1
kind: ReplicationController
metadata:
name: application-xyz-rc
spec:
replicas: 3
selector:
tier:front-end
template:
metadata:
label:
env:production
spec:
containers:
...

The content of this file is pretty similar for pods; the main difference is the kind of Docker Service that is specified. In this case, it uses the ReplicaController value. Later, we will define the desired number of replicas and the selector section can be used to specify labels.

Using this file, the replica can be created by running the kubectl create command, as follows:

kubectl create -f application-xyz-rc.yaml 

You can verify how pods are being created when required. You can delete a pod with the following command:

kubectl delete pod <pod-name>

You can then query the available pods with the following command:

kubectl get pod
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.40.189