هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
kubectl rollout history deploy/api -n shop
kubectl rollout undo deploy/api -n shop
deployment.apps/api rolled back
kubectl rollout status deploy/api -n shop
deployment "api" successfully rolled outrollout undo goes back one revision. For an older one: kubectl rollout undo deploy/api -n shop --to-revision=7.
Step by step
- See the revisions and what is in them:
kubectl rollout history deploy/api -n shop
REVISION CHANGE-CAUSE
7 image 1.4.2
8 image 1.4.3
kubectl rollout history deploy/api -n shop --revision=7The second command shows the full Pod template (image, env, resources) of revision 7.
- Roll back and watch it:
kubectl rollout undo deploy/api -n shop --to-revision=7
kubectl rollout status deploy/api -n shop --timeout=5mThe rollback is itself a new rollout (a new revision number, with the old template), so the normal rolling update and probes protect you.
- Check the running image:
kubectl get deploy api -n shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
registry.example.com/shop/api:1.4.2- Write the reason on each change so the history is readable next time:
kubectl annotate deploy/api -n shop kubernetes.io/change-cause="image 1.4.3, ticket OPS-311" --overwrite- Helm-installed app? Roll back the Helm release, not only the Deployment (otherwise the next
helm upgradebrings the bad version back):
- GitOps (Argo CD / Flux)? The cluster follows Git — a kubectl rollback is undone by the next sync. Roll back in Git: revert the commit that changed the image, and let Argo CD / Flux sync:
- Stop a bad rollout in the middle (pause, look, then decide):
Check that it worked
rollout status says successfully rolled out, all Pods run the old image, and your error rate and latency (dashboard, logs) are back to normal. Then write down what happened, and fix the bug in a new version.
Common problems
| Problem | Cause | Fix |
|---|---|---|
unable to find specified revision | Old ReplicaSets were cleaned up. | Keep more: spec.revisionHistoryLimit: 10; or deploy the old tag again. |
| The bad version comes back after some minutes | Argo CD / Flux or a CI job applies Git again. | Roll back in Git (revert) or in Helm. |
| Rollback done, still errors | The problem is not the image: a ConfigMap, Secret, DB migration or a dependency. | Check what else changed; ConfigMaps are not part of the revision. |
CHANGE-CAUSE is empty | Nobody set the annotation. | Annotate on each deploy (CI can do it). |
| Rollout hangs at "1 old replicas are pending termination" | New Pods are not ready (probe fails). | kubectl describe pod; fix the probe or roll back. |
| Database migration can not be undone | Schema changed in a non-backward-compatible way. | Make migrations backward compatible (expand, then contract). |
Go further
- Command pages: kubectl, helm, git.
- Next how-tos: Scale a deployment, Install an app with Helm, Find why a Pod does not start, Deploy with Argo CD from Git, Do a blue-green deployment in Kubernetes, Do a canary release in Kubernetes.
- Learn it: CKA — Rollouts, CKA — Helm upgrade and rollback, GitOps — Sync.
- Full guides: Argo CD, Helm.
- Practise: Lab: deploy with Argo CD, self-heal and a rollback.
1Why is a kubectl rollout undo not enough in a GitOps setup?
Argo CD / Flux apply what is in Git again; you must revert the change in Git.
2Are ConfigMap changes rolled back by rollout undo?
No. Only the Pod template of the Deployment; ConfigMaps and Secrets keep their current content.