Rolling Updates With Deployments
Let's see how to perform rolling updates with Deployments.
We'll cover the following
Rolling update
As well as self-healing and scaling, Deployments give us zero-downtime rolling updates.
As previously mentioned, Deployments use ReplicaSets for some of the background legwork. In fact, every time you create a Deployment, you automatically get a ReplicaSet that manages the Deployment’s Pods.
Note: Best practice states that you should not manage ReplicaSets directly. You should perform all actions against the Deployment object and leave the Deployment to manage ReplicaSets.
It works like this: You design applications with each discrete service as a Pod. For convenience – self-healing, scaling, rolling updates, etc. – you wrap Pods in Deployments. This means creating a YAML configuration file describing all of the following:
- How many Pod replicas
- What image to use for the Pod’s container(s)
- What network ports to use
- Details about how to perform rolling updates
You POST
the YAML file to the API server and Kubernetes does the rest.
Once everything is up and running, Kubernetes sets up watch loops to make sure the observed state matches the desired state.
All good so far.
Now, assume you’ve experienced a bug, and you need to deploy an updated image that implements a fix. To do this, you update the same Deployment YAML file with the new image version and re-POST it to the API server. This registers a new desired state on the cluster, requesting the same number of Pods, but all running the new version of the image. To make this happen, Kubernetes creates a new ReplicaSet for the Pods with the new image. You now have two ReplicaSets – the original one for the Pods with the old version of the image and a new one for the Pods with the updated version. Each time Kubernetes increases the number of Pods in the new ReplicaSet (with the new version of the image), it decreases the number of Pods in the old ReplicaSet (with the old version of the image). Net result: you get a smooth rolling update with zero downtime. And you can rinse and repeat the process for future updates – just keep updating that manifest file (which should be stored in a version control system).
Brilliant.
Get hands-on with 1200+ tech skills courses.