Rolling Deploy Behind the Load Balancer
Release with zero downtime in serial.
Rolling Deploy Behind the Load Balancer is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
Zero Downtime Is the Promise
Update all web nodes without dropping a single request. The trick is a rolling deploy: change a few hosts at a time. 🔄
serial Controls the Batch
Add serial to your play so Ansible works through hosts in small waves instead of all at once.
- hosts: web
serial: 1
tasks:
- import_role:
name: webappPercentages Work Too
serial accepts a percentage or a list of sizes, so you can ramp: a canary first, then larger batches.
serial:
- 1
- 25%
- 50%Drain Before You Touch
Before updating a node, take it out of rotation. Use delegate_to to tell the load balancer to stop sending it traffic.
- name: Drain node
community.general.haproxy:
state: disabled
host: "{{ inventory_hostname }}"
delegate_to: lb1Why delegate_to the LB
The web host cannot disable itself in the balancer; the load balancer must. delegate_to runs that task on lb1 for each web host.
Deploy the New Version
With the node drained, deploy code, render config and let a handler reload the app service for that host only.
- name: Pull release
ansible.builtin.git:
repo: "{{ app_repo }}"
version: "{{ app_version }}"
dest: /srv/app
notify: Reload appHealth Check Before Re-Enable
Confirm the node is healthy with uri before sending users back. Never re-add a broken host to the pool.
- name: Wait for health
ansible.builtin.uri:
url: http://localhost:8080/health
status_code: 200
retries: 5
delay: 3Re-Enable in the Balancer
Once healthy, put the node back into rotation, again via delegate_to the load balancer. Traffic flows to the new version.
- name: Enable node
community.general.haproxy:
state: enabled
host: "{{ inventory_hostname }}"
delegate_to: lb1max_fail_percentage Guards You
Set max_fail_percentage so the rollout halts if too many hosts fail, stopping a bad release from spreading further.
- hosts: web
serial: 1
max_fail_percentage: 20run_once for Shared Steps
Some steps, like a one-time db migration, should run a single time. Use run_once so only one host executes them.
- name: Migrate db
ansible.builtin.command: /srv/app/migrate
run_once: trueThe Whole Loop
Per host: drain, deploy, health-check, re-enable. serial repeats that loop in safe waves until the fleet is updated. ✅
Quick Check
One keyword makes the LB step work.
Recap
You built a rolling deploy: serial batches, drain and re-enable via delegate_to, health checks, and a fail guard. Zero downtime. 🟢
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Rolling Deploy Behind the Load Balancer” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Rolling Deploy Behind the Load Balancer”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “Rolling Deploy Behind the Load Balancer”?
Release with zero downtime in serial. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.
How long does the “Rolling Deploy Behind the Load Balancer” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Architect the Project: Roles & Inventory
- Provision, Harden & Bootstrap Hosts
- Rolling Deploy Behind the Load Balancer
- Smoke Tests, Rollback & Notifications