Skip to main content

Deployment: Rollout

A rollout occurs when a Deployment or StatefulSet updates its Pods to a new version. Kubernetes gradually replaces old Pods with new ones, following a defined strategy.

  • Ensures Zero Downtime: New Pods are created before terminating old ones.
  • Supports Rollback: Can revert to the previous version if needed.
  • Controlled Updates: Uses a strategy to limit impact.

By default when a deployment object is applied, kubernetes will do a rollout update to the existing pods.

Rollout Restart​

Whenever we want to restart pods because of new latest image is available or to fetch latest configuration from ConfigMap or Secret we can do a rollout restart.

➜ kubectl rollout restart deployment simple-go 
deployment.apps/simple-go restarted

And when you check the pods immediately after rollout restart you will see the process of rollout. The controller manager will spin up 1 new pods and as soon the new pods ready it will take down 1 pods until all new pods are ready.

➜ kubectl get pods                            
NAME READY STATUS RESTARTS AGE
simple-go-764bc77644-grfhg 1/1 Running 0 3h31m
simple-go-764bc77644-snb8n 1/1 Running 0 3h31m
simple-go-7cf4d4d6df-hgjv8 1/1 Running 0 5s
simple-go-7cf4d4d6df-hj7sk 0/1 ContainerCreating 0 2s

As we can see below after some time all olds pods already gone replaced by new sets of pods.

➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
simple-go-7cf4d4d6df-5ck9n 1/1 Running 0 30s
simple-go-7cf4d4d6df-hgjv8 1/1 Running 0 36s
simple-go-7cf4d4d6df-hj7sk 1/1 Running 0 33s

Rollout History​

To show list of deployment history we can use command rollout history deployment <name>.

➜ kubectl rollout history deployment simple-go
deployment.apps/simple-go
REVISION CHANGE-CAUSE
1 <none>
2 <none>
3 <none>

In here the CHANGE-CAUSE is empty because we need to explicitly specify the message in metadata.annotations.

Rollout Undo​

rollout undo will roll back existing deployment into previous version.

➜ kubectl rollout undo deployment simple-go

We can also also specify the revision based on the rollout history using --to-revision.

➜ kubectl rollout undo deployment simple-go --to-revision=2

References​