Deployment Revision history tracking¶
In Kubernetes, a Deployment Revision is automatically created each time a Deployment's Pod template is triggered to update.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md] This mechanism serves as an update history, allowing administrators to track changes and revert to previous states if necessary^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
Triggers for Revision creation¶
Not every update to a Deployment configuration results in a new revision entry.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
- Revisions ARE created: When a Deployment is first created or when the
spec.templatefield is updated^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]. - Revisions are NOT created: When only the
replicascount (scaling) or other parameters outside ofspec.templateare modified^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
Viewing history¶
To list the history of revisions for a specific Deployment, use the rollout history command^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
[kubectl](<./kubectl.md>) rollout history deployment <deployment-name>
To view specific details (such as the Pod template labels and container image) for a particular revision, append the --revision flag^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
[kubectl](<./kubectl.md>) rollout history deployment <deployment-name> --revision=<number>
Recording change causes¶
Users can annotate the history with the command used to perform the update.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
- Method: Add the
--recordflag to thekubectl applycommand^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]. - Result: The Kubernetes system saves the executed command line in the
CHANGE-CAUSEfield of the revision history^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]. - Note: The
--recordflag is currently deprecated, but remains in common use as a formal replacement has not yet been established^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
Rollback¶
Revision history tracking enables the recovery of a stable state in the event of a faulty deployment (e.g., an image pull error)^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
- Undo to previous: To revert to the immediately preceding revision^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
[kubectl](<./kubectl.md>) rollout undo deployment <deployment-name> - Undo to specific: To revert to a specific version number^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
[kubectl](<./kubectl.md>) rollout undo deployment <deployment-name> --to-revision=<number>
Related Concepts¶
- Kubernetes
- [[Rolling Update]]
- Blue-Green Deployment
- Canary Deployment
Sources¶
^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]