Rolling Updates with Kubernetes Deployments

Hands-On Lab

 

Photo of Will Boyd

Will Boyd

DevOps Team Lead in Content

Length

01:00:00

Difficulty

Intermediate

Deployments provide powerful automation for application management in Kubernetes. One of the things deployments can do is to allow you to perform rolling updates. Rolling updates enable you to update your containers to new versions gradually, without incurring downtime. In this lab, you will have a chance to learn, hands-on, how to perform a rolling update, as well as a rollback to previous version.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Rolling Updates with Kubernetes Deployments

The scenario

Our company's developers have just finished creating a new version of their candy-themed mobile game. They are ready to update the backend services that are running in our Kubernetes cluster. There is a deployment in the cluster managing the replicas for this application. The deployment is called candy-deployment. We'vee been asked to update the image for the container named candy-ws in this deployment template to a new version, linuxacademycontent/candy-service:3.

After you have updated the image using a rolling update, check on the status of the update to make sure it is working. If it is not working, perform a rollback to the previous state.

Get logged in

Use the credentials and server IP in the hands-on lab overview page to log in with SSH.

Perform a rolling update of the container version

Let's see the lay of the land before we go updating anything. Show our current deployments with:

[user@host]$ kubectl get deployments

We should see a table print out to the screen showing our candy-deployment.

Update deployment to the new version like so:

[user@host]$ kubectl set image deployment/candy-deployment candy-ws=linuxacademycontent/candy-service:3 --record

Check the progress of the rolling update:

[user@host]$ kubectl rollout status deployment/candy-deployment

If the update is not finished after a few minutes, something may be wrong with the update. Hit Ctrl C to kill our status command and get back to a prompt.

Roll back to the previous working state

In this scenario, the rolling update should fail. This is because the specified image, linuxacademycontent/candy-service:3, does not exist. Roll back to the previous version to get things working again.

Get a list of previous revisions:

[user@host]$ kubectl rollout history deployment/candy-deployment

Undo the last revision:

[user@host]$ kubectl rollout undo deployment/candy-deployment

Check the status of our pods:

[user@host]$ kubectl get pods

This should show that the broken pod is gone. Now check the status of the rollout:

[user@host]$ kubectl rollout status deployment/candy-deployment

This command should complete soon, saying the rollout was successful.