How to Perform a Rollback
Learn how to perform a rollback on a Deployment.
We'll cover the following...
As previously mentioned, Kubernetes keeps old ReplicaSets as a documented revision history and an easy way to roll back. Use the following widget to execute all the commands mentioned in this lesson:
apiVersion: apps/v1 kind: Deployment metadata: name: hello-deploy spec: replicas: 10 selector: matchLabels: app: hello-world revisionHistoryLimit: 5 progressDeadlineSeconds: 300 minReadySeconds: 10 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 template: metadata: labels: app: hello-world spec: containers: - name: hello-pod image: nigelpoulton/k8sbook:2.0 ports: - containerPort: 8080 resources: limits: memory: 128Mi cpu: 0.1
The following command shows the history of the Deployment with two revisions.
$ kubectl rollout history deployment hello-deploydeployment.apps/hello-deployREVISION CHANGE-CAUSE1 <none>2 <none>
Revision 1 was the initial release based on the 1.0 image. Revision 2 is the rollout that just updated the Pods to run version 2.0 of the image.
The following command shows the two ReplicaSets associated with each of the revisions.
$ kubectl get rsNAME DESIRED CURRENT READY AGEhello-deploy-5f84c5b7b7 10 10 10 27mhello-deploy-54f5d46964 0 0 0 93m
The next kubectl describe
command runs against the old ReplicaSet and proves its configuration still references the old image version. The output is trimmed, and the ReplicaSets will have different names. ... ...