Upgrading containers

In Kubernetes, applications are very easily updated. For this, Kubernetes uses rolling updates, which means that traffic to a container is first drained before the container is replaced. During an upgrade of the application, Kubernetes will deploy an additional pod and run it through some specified probes.

A probe is a diagnostic that is periodically performed on a pod to check its status. During the upgrading or creation of a pod, Kubernetes brings up the additional pod and makes sure that it passes the liveness and readiness probes.

If the newly created pod succeeds with both probes, the traffic to a single old pod is terminated and traffic to the new pod is opened. For this termination, Kubernetes uses a termination grace period. During this period, the 2 connection to the load balancer is stopped and active connections are processed successfully, and new traffic is routed to a running pod. The default grace period is 30 seconds, during which the pod will be in a termination state and all old traffic to this pod is redirected to the other pods.

This process continues until all pods are replaced with the new version. All of this is default behavior within Azure Kubernetes. A deployment is simply triggered by adjusting the deployment file and applying it with the same command as used previously:

Kubectl apply -f [file]

By default, httpGet probes are added to pods that are being exposed, but they can also be customized by adding the readiness probe or liveness probe to the deployment:

readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1

This readiness probe performs an httpGet request on the pod and has the following options:

  • path: The path it should call for the httpGet request.
  • port: The port number it should use for the call. This is also configured in our deployment file.
  • initialDelaySeconds: The seconds it waits before running the probe once the container is started.
  • periodSeconds: The number of seconds the probe waits before it times out.
  • successThreshold: The amount of success required for the probe minimum value is 1.

As mentioned, a deployment has a default rolling upgrade scenario configured. The configuration of the rolling deployment can be retrieved by using the following command:

kubectl describe deployment kubernetes-deployment
If you are interested in doing so, build a new version of your container and upgrade it within Kubernetes. Before running the upgrade, make sure you have the dashboard open and refresh the page during the update and you will see extra pods coming up and old pods being terminated.

In this section, we learned how to upgrade containers, which will help you stay up to date with the latest version. Moving forward, in the next section, we will look further into the scaling of containers and Kubernetes. 

..................Content has been hidden....................

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