DevOps Bootcamp · Lesson

Load Balancer Drain & Re-Enable

Take nodes out and back in safely.

Lesson 4 of 413 steps

Load Balancer Drain & Re-Enable is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 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.

Updating Live Traffic Is Risky

If you patch a server while users hit it, requests fail. The fix is to drain the node from the load balancer first. 🚦

What Draining Means

To drain a node is to stop sending it new traffic while letting in-flight requests finish. Then it is safe to update.

The Drain, Update, Re-Enable Cycle

The safe pattern is three steps: drain the node, deploy your change, then re-enable it in the load balancer.

Disable a Node in HAProxy

The community.general.haproxy module sets a backend node to disabled, telling HAProxy to stop routing traffic to it.

- name: Drain web node
  community.general.haproxy:
    state: disabled
    host: "{{ inventory_hostname }}"
    socket: /var/run/haproxy.sock

Run the LB Task From the LB

The HAProxy socket lives on the load balancer, so delegate_to the LB host while still naming the web node being drained.

  delegate_to: lb01

Wait for Connections to Drain

Give active requests time to finish. Use wait_for or a short pause so you do not cut off users mid-request.

- name: Let traffic drain
  ansible.builtin.wait_for:
    timeout: 30
  delegate_to: localhost

Now Deploy Safely

With the node out of rotation, run your update tasks: install packages, push config, restart the app. No live traffic is affected. 🔧

Re-Enable the Node

After updating, set the node back to enabled so HAProxy resumes routing traffic to your freshly deployed server.

- name: Re-enable web node
  community.general.haproxy:
    state: enabled
    host: "{{ inventory_hostname }}"
    socket: /var/run/haproxy.sock
  delegate_to: lb01

Health Check Before Re-Enabling

Confirm the app is actually up before adding it back. A wait_for or uri check on the health endpoint avoids serving a broken node.

- ansible.builtin.uri:
    url: http://localhost:8080/health
    status_code: 200
  retries: 5
  delay: 3

Do One Node at a Time

Pair this cycle with serial so only one or two nodes drain at once. The rest keep serving, giving you zero downtime.

- hosts: web
  serial: 1

Always Re-Enable, Even on Failure

Wrap the deploy in a block with always so a failed update still puts the node back into rotation instead of leaving it stranded.

Quick Check

Let us check the safe rollout pattern.

Recap

For zero downtime, drain a node, deploy, health-check, then re-enable, one node at a time with serial and an always block. ✅

Free to start

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 “Load Balancer Drain & Re-Enable” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Load Balancer Drain & Re-Enable”, 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 “Load Balancer Drain & Re-Enable”?

Take nodes out and back in safely. 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 4 of 4.

How long does the “Load Balancer Drain & Re-Enable” 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

  1. Automating Network Devices with cli_command
  2. delegate_to & run_once for Orchestration
  3. Coordinate Web, App & DB Tiers
  4. Load Balancer Drain & Re-Enable
← Back to DevOps Bootcamp