[Create a K8s cluster]
$ kind create cluster

[Create a Deployment]
$ kubectl create deployment test-nginx --image=nginx:1.18-alpine

$ kubectl get deploy,rs,po -l app=test-nginx

$ kubectl describe rs REPLICASET_NAME

$ kubectl describe po POD_NAME

$ kubectl scale deploy test-nginx --replicas=3

➤ Rolling Update Deployment
Let’s say you were having some issues with v18 of nginx and the v19 fixes it for you. 
Need to rollout a new update of nginx image to your pod.


$ kubectl set image deploy test-nginx nginx=nginx:1.19-alpine

We successfully updated all our pods to use nginx v19.

$ kubectl describe deploy test-nginx

➤ Rollback Deployment
Let’s assume the new nginx update has even more problems than the last one and now realized to switch to the old version. 
Time for a rollback to the previous version of nginx.
Kubernetes holds history of up to 10 ReplicaSet by default, we can update that figure by using revisionHistoryLimit on Deployment spec.

By now, we have made two changes to our Deployment test-nginx so the rollout history should be two.

$ kubectl get rs 

$ kubectl rollout history deploy test-nginx

$ kubectl rollout history deploy test-nginx --revision=1

$ kubectl rollout history deploy test-nginx --revision=2

Alright let’s get to rolling back our update to the previous rollout. 
We want to rollback to the stage where we were using nginx v18 which is rollout Revision 1.

$ kubectl rollout undo deploy test-nginx --to-revision=1

$ kubectl get deploy,rs,po -l app=test-nginx

Like the Rolling Update Deployment, the Rollback Deployment terminates the current pods and replaces them with the pods containing the spec from Revision 1.
If you check the rollout history once again, you can see that the Revision 1 has been used to create the latest pods tagging it with Revision 3.
There is no point in maintaining the same spec repeated for multiple revisions, so Kubernetes removes the Revision 1 since we have the latest Revision 3 of the same spec.

$ kubectl rollout history deploy test-nginx

$ kubectl rollout history deploy test-nginx --revision=2

$ kubectl rollout history deploy test-nginx --revision=3

Now we are back on the nginx v18 with the Rollback Deployment.

$ kubectl describe deploy test-nginx


[LINKS]
https://yankeexe.medium.com/how-rolling-and-rollback-deployments-work-in-kubernetes-8db4c4dce599
