Previously, I published an article about Deploying a Kubernetes Cluster on Oracle Ravello Cloud Platform and I hope you already enjoyed it. In this post I thought to share how to create a deployment, rolling updates and rolling them back if you see any issues after the updates.
Creating A Kubernetes Deployment
In my lab I deployed a Nginx deployment with 3 replicas and below is the yaml that I used for the deployment. It’s simple deployment but still good enough to test my rolling updates.
apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: "nginx:1.7.9" name: nginx
Before you proceed with the deployment, make sure to validate it with a yaml validator. I use “YAML Lint” validator to validate my deployments. if it is a valid yaml it will tell you or you will redirect to the line you have errors with.

First of all I checked the cluster and node status with “kubectl” prior to the deployment
kubectl get nodes
Created my yaml file as “nginx1.7.9.yaml”, then created a deployment with “kubectl” and pointing the file with “-f” flag
kubectl create -f [yaml_file]
Checked the Deployment
Kubectl get deployments
Make sure all your replicas in ready state, if not just wait and execute the same command again and see the status of replicas. See below screen capture from my console

Verified the deployment details with below command, you can see more details about the deployment such as created time stamp, labels, revision number, labels, selector, image version, events, etc. Here I have highlighted the information we need in later steps, but there are many details you can see about your deployment.
kubectl describe deployment [deployment name]

Deployment Rolling Updates
I updated the running Nginx version to 1.13.10 from my previous version 1.7.9, I randomly selected it from the list of later nginx versions.
Executed below command to set the running image to 1.13.10
kubectl set image deployment/[deployment_name] nginx=nginx:[new_version]
To check the rollout status use below command
kubectl rollout status deployment/[deployment_name]
Check the status of the rollout in the console

Check the deployment status with “kubectl describe” command

Rolling Updates Using YAML File
There is another method to rollout the updates. We have deployed our deployment using yaml file, simply edit the version in the yaml file using a text editor and reapply would do the job for us.

To reapply the changes use below command
kubectl apply -f [file]

You can check the rollout status from below piece of command
kubectl rollout status deployment/[deployment_name]

Checked the nginx version

Rolling Back The Kubernetes Deployment
So, let’s see how we can rollback the deployment updates to a previous version. We can’t expect always to be successful after an update and there can be many reasons to roll back an update after applying to a deployment
Remember, I mentioned “revision number” in the kubectl describe command and this is the place where it comes in to play. You can check the versions and some other important template details in deployments with the below command
kubectl rollout history deployment/nginx-deployment --revision=[revision_number]
See below output which I ran to all of the revisions which I had in my deployment updates

Roll back to the previous version with the revision number using the below command, here I posted the previous output to make it easy for you to read and understand

Check the deployment status again with the kubectl describe command. Please note that revision number will be updated and will not be the previous number. Just a note.

Just try it out if you need and you can take a copy of my Oracle Ravello Cloud blueprint to deploy a 4 node cluster easily from here. Your comments are always welcome, as always.
If You Found This Post As Useful Please Rate The Post And Share It!