Overview
As we discussed the pods and their manual deployment, I have to tell you something. Take a deep breath, ok…and sit probably :).
NO ONE WORKS WITH PODS
I will let that rest for a second….
Ok, now, what I mean. The reason, why no one works with pods is because, they are too granular. What if we need to put 5 replicas of that image on 5 workers. Well, there is something called Replication controller, which encapsulates the pod and add more features.
So let's see visual representation of what I mean:
With the replication controller, we can define N amount of replicas and the controller takes care of the rest. The controller will ensure our desired state (5 replicas) is always in place.
So how we do it ? Well the process is pretty similar to pods as it relies on them.
- We create a manifest file
- We present it to the API
- The API do the rest
Configuration
As with the manual configuration of the pods, we have to prepare a little manifest file. I have prepared a simple one:
Manifest File
Manifest file
apiVersion: v1 kind: ReplicationController metadata: name: hello-rc spec: replicas: 5 selector: app: hello-date template: metadata: labels: app: hello-date spec: containers: - name: hello-pod image: andonovj/httpserverdemo:latest ports: - containerPort: 1234
The first information is about the replication controller. In our case:
- it is Version 1
- it is Replication Controller (you to believe :) )
- It is called: “hello-rc”
- It has 5 replicas, so it will configure 5 pods
- It will run application called: “hello-date” defined in the template
Later we have a pod a template section which has:
- Metadata
- Specification
From here, you can orient I hope :)
You see that the replication controller gives us way more possibilities and furthermore it relies on the Pods as it is using them.
Create Replication Controller
The command to create the controller, once you have the YML/JSON file is pretty similar as the pod:
Create RC
ubuntu@k8s-master:~$ kubectl create -f rc.yml replicationcontroller/hello-rc created ubuntu@k8s-master:~$
After that, we can check the status and the pods
Create RC
ubuntu@k8s-master:~$ kubectl get rc NAME DESIRED CURRENT READY AGE hello-rc 5 5 3 17s ubuntu@k8s-master:~$ kubectl describe rc Name: hello-rc Namespace: default Selector: app=hello-date Labels: app=hello-date Annotations: <none> Replicas: 5 current / 5 desired Pods Status: 5 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app=hello-date Containers: hello-pod: Image: andonovj/httpserverdemo:latest Port: 8080/TCP Host Port: 0/TCP Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 10m replication-controller Created pod: hello-rc-dlx7j Normal SuccessfulCreate 10m replication-controller Created pod: hello-rc-2kqmm Normal SuccessfulCreate 10m replication-controller Created pod: hello-rc-twz2w Normal SuccessfulCreate 10m replication-controller Created pod: hello-rc-8rn9t Normal SuccessfulCreate 10m replication-controller Created pod: hello-rc-j2swd ubuntu@k8s-master:~$
In our case, we have 5 pods on our 2 workers:
- 2 on Worker 1
- 3 on Worker 2
Update Configuration
We can update the configuration, by simply updating the YML/JSON file. For example, let's increase the replicas from 5 → 10, firstly we update it in the YML/JSON file:
Update Config
spec: replicas: 10
After that, we simply apply that change:
Apply the changes
ubuntu@k8s-master:~$ kubectl apply -f rc.yml Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply replicationcontroller/hello-rc configured ubuntu@k8s-master:~$
You can ignore the warning line :) You can check the configuration as follows:
Check the status
ubuntu@k8s-master:~$ kubectl get rc NAME DESIRED CURRENT READY AGE hello-rc 10 10 10 16m ubuntu@k8s-master:~$ kubectl describe rc Name: hello-rc Namespace: default Selector: app=hello-date Labels: app=hello-date Annotations: Replicas: 10 current / 10 desired Pods Status: 10 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app=hello-date Containers: hello-pod: Image: andonovj/httpserverdemo:latest Port: 1234/TCP Host Port: 0/TCP Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 16m replication-controller Created pod: hello-rc-dlx7j Normal SuccessfulCreate 16m replication-controller Created pod: hello-rc-2kqmm Normal SuccessfulCreate 16m replication-controller Created pod: hello-rc-twz2w Normal SuccessfulCreate 16m replication-controller Created pod: hello-rc-8rn9t Normal SuccessfulCreate 16m replication-controller Created pod: hello-rc-j2swd Normal SuccessfulCreate 73s replication-controller Created pod: hello-rc-zhngb Normal SuccessfulCreate 73s replication-controller Created pod: hello-rc-vxzfl Normal SuccessfulCreate 73s replication-controller Created pod: hello-rc-dklgj Normal SuccessfulCreate 73s replication-controller Created pod: hello-rc-cf8jw Normal SuccessfulCreate 72s replication-controller Created pod: hello-rc-6tg65 ubuntu@k8s-master:~$
You see that some pods are newer than other, these are the newly created ones :)
Rolling-Updates
TODO