Kubernetes Certification Training Course : Lecture 3

What is the purpose of running multiple pods ? High availability and load balancing. Kubernetes Controllers help to maintain pods availability and desired state. For example, if one Pod gets deleted, another one is created automatically.

There are different types of Controllers:

  • RC (Replication Controller)
  • RS (Replica Set)
  • Deployment
  • DaemonSet
  • Job
  • CronJob

How, let’s say, Replication Controller is created ? Let’s look at the yaml script below :

apiVersion: v1
kind: ReplicationController
metadata:
  name: tomcatrc
spec:
  replicas: 3
  selector:
    app: tomcat
  template:
    metadata:
      name: tomcat
      labels:
        pod: tomcatrc
        app: tomcat
    spec:
      containers:
      - name: tomcat
        image: lerndevops/tomcat:8.5.47
        ports:
        - containerPort: 8080

Replication Controller has the name tomcatrc and has 3 replicas. And who will be the members of Replication Controller team ? For this purpose selector is used. In the example if any pod has the label ‘app=tomcat’, RC takes it into the Controller. If there are no pods in the cluster that match the clause, then template section is used for creating pods. If there are pods in the cluster that match the clause (label ‘app=tomcat’), then Replica Controller will reduce number of replicas to create. If there are more pods that match the clause than required by Replica Controller, then Replica Controller will not create, but just reduce the number of pods to match the clause.

kubectl get rc – command that shows replication controllers defined in the cluster

kubectl describe rc <replication controller name> – command that shows detailed information about replication controller

If one or more of “controlled” pods is/are deleted, then Replication Controller recreates pods due to its template.

The main goal of Replication Controller is to maintain the number of replicas. Controller is just a management object, it is not equal to Pod.

kubectl scale rc <replication controller name> –replicas=<number of replicas> – command that defines the new number of replicas in the Replication Controller. New pods get created after changing replicas value, or excessive pods get deleted – all for reaching the number of pods matching replicas value.

kubectl delete rc  <replication controller name> – command that deletes replication controller along with all matching pods

Nowadays Replication Controller tends to be used rarely, because Replica Set is a better approach. Replication Controller requires equity match in selector section (app=tomcat in the example). Replica Set allows defining more flexible clause : matchLabels subsection in selector section with one or more labels listed under (see here) or matching expressions (see here). Apart from that, Replica Controller and Replica Set are the same.

Services can be created not for separate pods but for Replica Set/Replica Controller also. Command syntax is the same as for Pod, except that rs and rs name are used instead of pod and pod name. In the wake the number of Endpoints generated when creating a Service for RS/RC equals to number of replicas in RS/RC. When accessing the Replica Set/Replica Controller via Service, any underlying Pod can be used. This is how load balancing across multiple pods is achieved. Load balancing is provided by Service.

kubectl get ep <service name> – command that shows all given service endpoints

Multiple yamls can be created in a single file – see here. Three dashes are used as a separator.

Previous Next

Leave a Reply

Your email address will not be published. Required fields are marked *