如何使用kubectl查看Deployment历史版本的详细信息?
Great question! I’ve faced this exact frustration before—seeing just version numbers in kubectl rollout history gives you zero context to decide which version to roll back to. Here are the key commands and tips to get the detailed info you need:
1. Inspect a Specific Revision’s Full Details
To dive into the complete configuration of a single revision, add the --revision flag to your history command, specifying the version number you want to check:
kubectl rollout history deployment/myDeployment --revision=2
This will output the full spec of that Deployment revision, including:
- Container image versions
- Resource requests/limits
- Environment variables
- Annotations (including any change cause notes)
- Pod template configurations
2. Quick Comparison of All Revisions (Custom Columns)
If you want a high-level overview of all revisions side-by-side (like comparing image versions across every rollout), use a custom column output to extract specific fields:
kubectl rollout history deployment/myDeployment -o custom-columns='REVISION:.revision,IMAGE:.spec.template.spec.containers[0].image,CHANGE CAUSE:.metadata.annotations.kubernetes\.io/change-cause'
You can adjust the columns to include whatever fields matter most to you—swap IMAGE for .spec.replicas to track replica count changes, or add .spec.template.spec.nodeSelector to check node placement updates.
3. Add Context to Future Rollouts
To make your rollout history more useful going forward, document changes explicitly:
- In newer Kubernetes versions (where
--recordis deprecated), add a custom annotation when updating your Deployment:
This annotation will show up in your rollout history, giving you instant context for each revision without needing to dig into full specs.kubectl set image deployment/myDeployment mycontainer=myimage:v3 --annotations kubernetes.io/change-cause="Updated to v3: fixed API timeout bug"
内容的提问来源于stack exchange,提问作者Satyajit Das

