Skip to content

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.template field is updated^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
  • Revisions are NOT created: When only the replicas count (scaling) or other parameters outside of spec.template are 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 --record flag to the kubectl apply command^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
  • Result: The Kubernetes system saves the executed command line in the CHANGE-CAUSE field of the revision history^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md].
  • Note: The --record flag 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>
    

Sources

^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]