RollingUpdate – Managing Advanced Kubernetes Resources

When you update the Deployment with a RollingUpdate strategy, Kubernetes creates a new ReplicaSet resource, and it simultaneously spins up the required number of pods on the new ReplicaSet resource while slowly spinning down the old ReplicaSet resource, as evident from the following diagram:

Figure 6.3 – RollingUpdate strategy

RollingUpdate is the default deployment strategy. You can use the RollingUpdate strategy in most applications, apart from ones that cannot tolerate more than one version of the application at a given time.

Let’s update the nginx Deployment resource using the RollingUpdate strategy. We will reuse the standard nginx-deployment.yaml file that we used before. Use the following command and see what happens to the ReplicaSet resources:

$ kubectl apply -f nginx-deployment.yaml && kubectl get replicaset -w deployment.apps/nginx configured

NAMEDESIREDCURRENTREADYAGE
nginx-6799fc88d833349s
nginx-6889dfccd51114s
nginx-6799fc88d822253s
nginx-6889dfccd52228s
nginx-6799fc88d811157s
nginx-6889dfccd533311s
nginx-6799fc88d800060s

As we see, the old ReplicaSet resource—nginx-6799fc88d8—is being rolled down, and the new ReplicaSet resource—nginx-6889dfccd5—is being rolled out simultaneously.

The RollingUpdate strategy also has two options—maxUnavailable and maxSurge.

While maxSurge defines the maximum number of additional pods we can have at a given time, maxUnavailable defines the maximum number of unavailable pods we can have at a given time.

Tip

Set maxSurge to 0 if your application cannot tolerate more than a certain number of replicas. Set maxUnavailable to 0 if you want to maintain reliability and your application can tolerate more than the set replicas. You cannot specify 0 for both parameters, as that will make any rollout attempts impossible. While setting maxSurge, ensure your cluster has spare capacity to spin up additional pods, or the rollout will fail.

Using these settings, we can create different kinds of custom rollout strategies—some popular ones are discussed in the following sections.

Related Posts

Static provisioning – Managing Advanced Kubernetes Resources-2

As the Service resource is created, we can create a StatefulSet resource that uses the created PersistentVolume and Service resources. The StatefulSet resource manifest, nginx-manual-statefulset.yaml, looks like…

Static provisioning – Managing Advanced Kubernetes Resources-1

Static provisioning is the traditional method of provisioning volumes. It requires someone (typically an administrator) to manually provision a disk and create a PersistentVolume resource using the…

StatefulSet resources – Managing Advanced Kubernetes Resources

StatefulSet resources help manage stateful applications. They are similar to Deployment resources, but unlike a Deployment resource, they also keep track of state and require Volume and…

Managing stateful applications – Managing Advanced Kubernetes Resources

Imagine you’re a librarian in a magical library. You have a bunch of enchanted books that store valuable knowledge. Each book has a unique story and is…

Horizontal Pod autoscaling – Managing Advanced Kubernetes Resources-2

Now, let’s autoscale this deployment. The Deployment resource needs at least 1 pod replica and can have a maximum of 5 pod replicas while maintaining an average…

Horizontal Pod autoscaling – Managing Advanced Kubernetes Resources-1

Imagine you’re the manager of a snack bar at a park. On a sunny day, lots of people come to enjoy the park, and they all want…

Leave a Reply

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