Sooner or later a release breaks something. A rollback returns the service to a version that is known to work. The time to plan it is before you need it.
What you need
- The previous artifact, still stored.
- A record of which version was running before.
- The configuration that went with it.
- A tested way to deploy it.
Rolling back usually means deploying the old artifact again, not rebuilding old source. A rebuild may not give the same result.
With a symbolic link
If each version has its own directory, switching back is quick:
ln -sfn 1.3.0 /srv/shop/current
readlink /srv/shop/current1.3.0A running program usually keeps using the old files until you restart or reload it.
With containers
Run the previous image again, ideally by digest. Replace the placeholder:
docker stop shop && docker rm shop
docker run -d --name shop -p 8080:8080 \
registry.example.com/shop@sha256:<previous-digest>Use the same options and settings as that version had. There is a short gap here while no container is running.
In Kubernetes, a Deployment keeps earlier revisions:
kubectl rollout history deployment/shop
kubectl rollout undo deployment/shop
kubectl rollout status deployment/shopundo returns to the previous revision of the pod template. It does not restore your database, and changes to separate objects such as a ConfigMap are not undone with it.
The database problem
Code is easy to replace, data is not. If the new version renamed or deleted a column, the old code may fail against the changed database. A safer method is expand and contract: first add the new structure while keeping the old, move the application over, and remove the old part only in a later release. Always have tested backups.
Roll back or fix forward
Rolling back is often best when users are affected and the old version is safe. Fixing forward means releasing a new correction, which may be the only choice after a one-way data change. Either way, verify with a health check afterwards and write down what happened.
Try it
Make directories v1 and v2, each with a version.txt. Point current at v2 with ln -sfn v2 current, read current/version.txt, then switch back to v1. Time how long it takes. The files and links lab covers links in a live shell.
Check your understanding
Rollbacks
All 3 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.