Rolling Updates in Swarm
Imagine upgrading a fleet of buses. Instead of replacing all buses at once (causing chaos), you replace them one by one while the rest continue running. This way, passengers always have transport. In Docker Swarm, rolling updates work the same way — containers are updated gradually, ensuring the service stays available.
Deployment Foundations
1. What are Rolling Updates?
- A rolling update updates service replicas one at a time (or in batches).
- Ensures continuous availability during updates.
- Controlled by parameters like update delay, parallelism, and failure action.
2. Key Parameters for Rolling Updates
- --update-parallelism: Number of tasks updated at once.
- --update-delay: Time delay between updates.
- --update-failure-action: What to do if an update fails (
pause,continue,rollback). - --update-order: Order of updates (
start-firstorstop-first).
3. Benefits of Rolling Updates
- Zero Downtime: Services remain available during updates.
- Controlled Risk: Gradual rollout reduces impact of failures.
- Flexibility: Customize speed and behavior of updates.
4. Rolling Update Workflow
- Deploy a service.
- Update the service with new image or configuration.
- Swarm replaces tasks gradually according to update parameters.
- Monitor progress and rollback if needed.
Things to Remember
- Rolling updates are essential for production reliability.
- Parameters allow fine‑grained control over rollout speed and failure handling.
- Rollbacks ensure safety if updates fail.
Hands‑On Lab
Step 1: Deploy a Service
docker service create --name web --replicas 3 -p 8080:80 nginx:1.19
Step 2: Update the Service with Rolling Update Parameters
docker service update \
--image nginx:1.21 \
--update-parallelism 1 \
--update-delay 10s \
--update-failure-action rollback \
web
- Updates one replica at a time.
- Waits 10 seconds between updates.
- Rolls back if update fails.
Step 3: Monitor Update Progress
docker service ps web
Step 4: Test Rollback
docker service update --image nginx:broken web
- Swarm detects failure and rolls back automatically.
Practice Exercise
- Deploy a service
frontendwith 4 replicas of Nginx version1.19. - Update it to version
1.21with:- Parallelism = 2
- Delay = 5s
- Failure action = pause
- Observe how updates happen in batches.
- Simulate a failure and test rollback.
- Reflect on how rolling updates ensure reliability.
Visual Learning Model
Service: web (nginx)
├── Replica 1 → updated
├── Replica 2 → updated after delay
├── Replica 3 → updated after delay
Rolling update ensures gradual replacement with zero downtime
The Hackers Notebook
Rolling updates in Swarm allow services to be upgraded gradually, ensuring zero downtime and controlled risk. Parameters like parallelism, delay, and failure action provide flexibility. Rollbacks safeguard against failures, making rolling updates a cornerstone of reliable production deployments.
