HAProxy + Keepalived¶
This page is the starting point for HAProxy and keepalived in 2025.1. The loadbalancer role is applied by the "Apply
role loadbalancer" play to the loadbalancer group (the network nodes of the example inventory,
inventory/multinode:84-85), restricted to enable_loadbalancer_True, with play tags haproxy, keepalived and
loadbalancer and a max_fail_percentage (site.yml:105-120). It runs the containers haproxy, keepalived
(enable_keepalived, default: follows enable_haproxy), proxysql (enable_proxysql, default yes in 2025.1)
and haproxy_ssh (only with enable_letsencrypt, default no) (roles/loadbalancer/defaults/main.yml:2-36,
group_vars/all.yml:836-837, :958, :913). The same play holds 38 per-service include_role … tasks_from:
loadbalancer tasks (39 in 2024.1: swift is gone), run only for deploy, reconfigure, upgrade and config
(site.yml:121-327); each of them also carries its service tag. A service's loadbalancer.yml imports
loadbalancer-config, which renders the HAProxy frontend through haproxy-config and, with enable_proxysql, the
ProxySQL users and rules through proxysql-config (roles/loadbalancer-config/tasks/main.yml:2-8). The hacluster
role is a separate play and is not covered here; nor is the letsencrypt play (site.yml:329-341), except where it
touches HAProxy. The lists below say where the study covers how to operate it, its impact, its dependencies and the
evidence, what to check around a run and what stays open; the service card follows them.
Note
Changed in 2025.1 CODE
- Who restarts HAProxy: no config task of
loadbalancerorhaproxy-confignotifies a handler any more; the role'scheck-containers.ymlimportsservice-check-containers(roles/loadbalancer/tasks/check-containers.yml:2-3), which notifiesRestart <name> containeronly for the containerscompare_containerreports changed. That check runs once, at the end of the loadbalancer play (site.yml:319-324), which carries only the play tags. So-t <service>rewrites the service's frontend file but no longer restarts HAProxy; the new frontend applies at the next run of the play with-t haproxy,-t loadbalanceror no tag (F18). - ProxySQL on by default:
enable_proxysql: "yes"(group_vars/all.yml:958), so themariadbHAProxy frontend is skipped and database traffic goes through ProxySQL on the internal VIP (roles/loadbalancer-config/defaults/main.yml:2). New ProxySQL tuning defaults, and on single-node database shards a 10-secondshun_on_failuresdelay (roles/loadbalancer/defaults/main.yml:203-237). The upgrade from a 2024.1 cloud that ran without ProxySQL is covered on MariaDB/Galera. - TLS 1.3 only by default:
kolla_haproxy_ssl_settings: "modern"(group_vars/all.yml:441) rendersno-tlsv12on the bind and server sides (group_vars/all.yml:443, :457-461,roles/loadbalancer/templates/haproxy/haproxy_main.cfg.j2:16-18).intermediateorlegacyrestore older settings. Which clients break is NOT AVAILABLE from the code. - Layer-7 health checks: the
haproxydicts of 28 roles now addoption httpchkto their HTTP backends (e.g.roles/keystone/defaults/main.yml:21; one role in 2024.1). haproxy_run.shexecs HAProxy with-f /etc/haproxy/services.d/instead of piping the file list throughxargs(roles/loadbalancer/templates/haproxy/haproxy_run.sh.j2:38), so HAProxy replaces the shell and receives the container's stop signal (Kolla images §2.6).- Keepalived ProxySQL check:
check_alive_proxysql.shnow runsmariadb … -e "SELECT 1"on the ProxySQL admin socket with the admin password (roles/loadbalancer/templates/keepalived/check_alive_proxysql.sh.j2:6-12); the keepalived image gains the MariaDB client (kolladocker/keepalived/Dockerfile.j2:10-20). The check-script tasks no longer notify keepalived (roles/loadbalancer/tasks/config.yml:74-105). - Certificates: the PEM copies moved to
copy-certs.yml, which runs whenloadbalancer_copy_certsis true and followsletsencrypt_managed_certs(roles/loadbalancer/tasks/config.yml:180-182,roles/loadbalancer/tasks/copy-certs.yml:2-32,roles/loadbalancer/defaults/main.yml:203,group_vars/all.yml:518). The certificate rotation for Let's Encrypt is unchanged in principle, under a new script name,update-loadbalancer-cert(kolladocker/letsencrypt/letsencrypt-lego/sync-and-update-certificate.sh:84, :89,docker/haproxy/haproxy-ssh/update-loadbalancer-cert.sh:23, :50). - Single external frontend: the role default was renamed to
haproxy_single_external_frontend_public_port(roles/loadbalancer/defaults/main.yml:195), the namegroup_vars/all.yml:1068sets, so the 2024.1 port mismatch between the frontend and the endpoints is gone. - Handlers: the same staged sequence; the two "wait for backup" handlers are now
any_errors_fatal(roles/loadbalancer/handlers/main.yml:115-119,:150-154), so a backup HAProxy or ProxySQL that does not come back stops the play on every host. The loadbalancer handlers keep theirkolla_action != "config"guards. - Since 2024.1, unchanged: the
haproxy_sshcontainer for Let's Encrypt, HAProxy's own Prometheus metrics on port 9101,haproxy_threads, HTTP/2 on TLS binds.
Where to look¶
Operate¶
- Scenario: Reconfigure a single service
§2
(
-t haproxy reconfigureon an unchanged cloud) - Command: Reconfigure a single service §1.2, Command quick lookup by tag
Impact and risk¶
- What the tag executes (
haproxy): Tags §3 and Tags §3.1, rowshaproxy; the loadbalancer play under a service tag: Tags §2.3 - Risks: R8
Dependencies¶
- Dependencies: Component dependencies §1, Component dependencies §2
Evidence¶
- Fact sheet: fact sheet A §1
(the
loadbalancerrole in 2025.1);haproxy-config: fact sheet A §2 - Image side: Kolla images §5 (rows
haproxy,keepalived) - Also: handlers: Tags §5; deployment order: Deployment execution flow
Before and after a run¶
- Pre-execution checklist, step 5 (health gates): before the run, check HAProxy backends all UP. Repeat after each batch.
- Pre-execution checklist, step 7 (scope): add
--skip-tags haproxywhen the frontends are not meant to change; it skips the whole loadbalancer play, whose three play tags arehaproxy,keepalivedandloadbalancer(site.yml:115-118). - Tags §3.1, row
haproxy: the restart handlers run only when the final check finds a container changed (site.yml:319-324,roles/service-check-containers/tasks/main.yml:34-41) CODE; with a change, prefer a window. Prerequisites: facts of every backend host; certificates if TLS is on and Let's Encrypt does not manage them (roles/loadbalancer/tasks/precheck.yml:58-94). - First 2025.1 run on a 2024.1 cloud: expect the restart handlers.
compare_containerreports a unit file written by 2024.1 (F16), and the rendered files change (TLS settings,haproxy_run.sh, the ProxySQL check script, layer-7 checks in most frontends, CA entries inconfig.json); the shared check then notifiesRestart <name> containerfor each changed container, which starts the staged sequence below for haproxy, proxysql and keepalived CODE. With ProxySQL newly enabled, theproxysqlcontainer is created on that run. -
R8, the restart order, still staged in 2025.1. Handlers run in their definition order, and each
listens toRestart haproxy container,Restart proxysql containerorRestart keepalived containerCODE:- on every host of the batch, read the API interface addresses and group the hosts by whether they hold
kolla_internal_vip_address(roles/loadbalancer/handlers/main.yml:9-34); - on the backup hosts: stop keepalived (keepalived change only,
:36-49), stop haproxy (haproxy or keepalived change,:54-68), stop proxysql (any of the three,:70-88), start haproxy and wait forhaproxy_monitor_port(haproxy or keepalived change,:90-118), start proxysql when enabled and wait for its admin port (any of the three,:121-153), start keepalived (keepalived change only,:156-177); - on the VIP holder: stop haproxy (haproxy or keepalived change,
:181-195), stop proxysql (proxysql or keepalived change,:197-210), stop keepalived (keepalived change only,:212-224), then start them again in the same order, waiting for each port (:226-307); - after a keepalived start, wait for haproxy and, when enabled, proxysql to answer on the internal VIP
(
:309-331); - last:
Restart haproxy-ssh container, on every host at once, with no backup/VIP split (:333-347), notified by the shared check when the haproxy-ssh container changed.
Every stop and start handler is skipped for
kolla_action == "config", and the wait handlers are notified only by the start handlers. An haproxy-only change therefore stops HAProxy on the VIP holder while its keepalived keeps running; whether the VIP moves meanwhile, and for how long clients fail, is NOT AVAILABLE (keepalived semantics). Precautions: see R8;--skip-tags haproxywhen you don't intend to change frontends. - on every host of the batch, read the API interface addresses and group the hosts by whether they hold
-
R22, inventory reordering (loadbalancer, mariadb, glance, nova-conductor, keystone groups): keepalived priorities change (priority = position in
loadbalancer+ 1,roles/loadbalancer/templates/keepalived/keepalived.conf.j2:15, stillstate BACKUPandnopreempt,:11-12). Precautions: treat inventory order as configuration; never reorder casually. - Reconfigure a single service
§3,
verification of
-t <svc> reconfigure: before, a diff of/etc/kolla/haproxy/services.d/<svc>*.cfg(and, with the single external frontend, of/etc/kolla/haproxy/external-frontend-map) against the previous version. Changed in 2025.1: the service's frontend file and its map block notify nothing (roles/haproxy-config/tasks/main.yml:2-21, :23-49), so after a service-tagged run HAProxy still serves the old frontend; apply it with-t haproxyand check withdocker ps --filter name=haproxythat HAProxy restarted (F18) CODE. - Upgrade from 2023.1 (still in the 2025.1 role):
upgradestops and removesprometheus_haproxy_exporterbefore the deploy tasks (roles/loadbalancer/tasks/upgrade.yml:4-21);deployandreconfiguredo not (roles/loadbalancer/tasks/deploy.yml:2-6,reconfigure.yml:2). The old exporter listened on the same port 9101 that HAProxy's ownlisten metricsnow binds (group_vars/all.yml:670,roles/loadbalancer/templates/haproxy/haproxy_main.cfg.j2:46-51) CODE; what happens if adeployruns while the old container still holds the port is NOT AVAILABLE. - Overrides: an override of the old role default
haproxy_external_single_frontend_public_portis now ignored; sethaproxy_single_external_frontend_public_portinstead (roles/loadbalancer/defaults/main.yml:195) CODE. To keep TLS 1.2 clients working, setkolla_haproxy_ssl_settings: intermediatebefore the first 2025.1 run (group_vars/all.yml:441-443).
Known limits and open points¶
- Known bugs and limitations, row
haproxy, read against 2025.1: restart instead of reload still holds (the image'skolla_ensure_haproxy_latest_config, kolladocker/haproxy/haproxy/Dockerfile.j2:17, is never called fromansible/, Kolla images §5); only Let's Encrypt certificates are reloaded without a restart, through the admin socket (above). Staleservices.dfiles are still never removed (haproxy-configonly templates,roles/haproxy-config/tasks/main.yml:2-21; the only removal ismariadb.cfgwhen ProxySQL is enabled,roles/loadbalancer/tasks/config.yml:63-72, which now applies by default); keepalived priority still comes from inventory order;upgradeis still thedeploytask flow, now preceded by the exporter removal (roles/loadbalancer/tasks/upgrade.yml:21). Status: CODE. - Stale files, since 2024.1: turning
haproxy_single_external_frontendoff leavesservices.d/external-frontend.cfgin place (it is only templated when the option is on,roles/loadbalancer/tasks/config.yml:143-153), and HAProxy loads every file ofservices.d(roles/loadbalancer/templates/haproxy/haproxy_run.sh.j2:38); a disabled service's block also stays inexternal-frontend-map(blockinfileruns only for enabled services,roles/haproxy-config/tasks/main.yml:43-47). Status: CODE. - Single external frontend, one point to check before enabling it CODE: the map is copied into the container
when external TLS is on and Let's Encrypt does not manage the external certificate, or when Let's Encrypt is off
(
roles/loadbalancer/templates/haproxy/haproxy.json.j2:22-28; it isoptionalonly when the option is off), while the frontend always reads/etc/haproxy/external-frontend-map(roles/loadbalancer/templates/haproxy/haproxy_external_frontend.cfg.j2:11). The 2024.1 port mismatch is fixed: frontend and endpoints both usehaproxy_single_external_frontend_public_port(haproxy_external_frontend.cfg.j2:10,group_vars/all.yml:1068). - Known bugs and limitations, second row
site.yml: the placement loadbalancer include still lackswhen: enable_placement(site.yml:248-251), as in 2024.1. Status: CODE. - Q5: "HAProxy restart: VIP behaviour". Status: NOT AVAILABLE.
- What is not known, row "HAProxy restart": the sources do not establish whether keepalived drops or moves the VIP, and for how long; whether the node goes to FAULT; whether established connections are cut; whether nova and neutron get DB errors and instance metadata requests fail meanwhile; how HAProxy treats backends that are not up yet on a first deploy.
- F3, "
docker_graceful_timeoutanddocker_client_timeoutare ignored": does not hold since 2024.1; containers stop through their systemd unit withdocker_graceful_timeout(R24) CODE. Changed in 2025.1:haproxy_run.shnowexecs HAProxy (roles/loadbalancer/templates/haproxy/haproxy_run.sh.j2:38), so HAProxy gets the stop signal directly; what it does with in-flight connections in its-Wmaster-worker mode is NOT AVAILABLE (HAProxy semantics). - fact sheet A §1.8, "Operationally notable behaviour", read against 2025.1: any change means a full restart of haproxy, never a reload, staged backups
first and VIP holder last (R8 above); whether a haproxy restart causes VIP failover or a VIP outage is NOT AVAILABLE; keepalived priority depends on inventory order; stale frontends are never removed;
-t haproxydoes not runcommon(commonis its own play,site.yml:88-103); non-local bind is still set by the role, now through thesysctlrole with the same values and the sameKOLLA_UNSET/KOLLA_SKIPhandling (roles/loadbalancer/tasks/config-host.yml:8-18,roles/sysctl/tasks/main.yml:7-20, withset_sysctl); VRRP router id collisions:keepalived_virtual_router_idstill defaults to51(group_vars/all.yml:247);keepalived_traffic_mode: unicastis still available (defaultmulticast,roles/loadbalancer/defaults/main.yml:62,keepalived.conf.j2:17-29) CODE. - fact sheet A §2.4, "Notable" for the
haproxy-configrole: stale files are not removed; the file of a service whoseenabledis false is left as it was; file name; facts are required; precedence. Since 2024.1: the map block per service (above). - Kolla images §6, item 15: the VIP follows the HAProxy stats
socket, and the ProxySQL admin socket when ProxySQL is enabled (one
check_alive_<service>.shper enabled service,roles/loadbalancer/tasks/config.yml:93-111;vrrp_scriptwithinterval 2,fall 2,rise 10,keepalived.conf.j2:1-8) CODE. Since 2024.1: with no script under/checks,check_alive.shdoes not test the HAProxy socket and reaches its end without a failing check (kolladocker/keepalived/check_alive.sh:9-33). Changed in 2025.1: the ProxySQL check logs in with the admin password instead of a socketshow info(roles/loadbalancer/templates/keepalived/check_alive_proxysql.sh.j2:6-12), so a wrongproxysql_admin_passwordmakes the check fail and can move the VIP; and akeepalived.confor check-script change no longer restarts keepalived by itself unless the check step finds the container changed. Withkeepalived_track_script_enabled: falsethere is novrrp_scriptat all (roles/loadbalancer/defaults/main.yml:190,keepalived.conf.j2:1-8, :45-49). Whether an HAProxy restart puts the node in FAULT, and for how long, is NOT AVAILABLE (keepalived semantics). - ProxySQL, on by default in 2025.1 CODE:
loadbalancer-configskips the HAProxy frontend ofmariadbwhen ProxySQL is on (roles/loadbalancer-config/defaults/main.yml:2); the ProxySQL backends now usemariadb_port(roles/loadbalancer/templates/proxysql/proxysql.yaml.j2:87), which defaults todatabase_port(group_vars/all.yml:538). An haproxy change also stops and starts proxysql on the backup hosts, not on the VIP holder (roles/loadbalancer/handlers/main.yml:83-87, :141-146, :197-210).
Service card¶
The rows of the card are explained in How to read a service card.
| Item | Value |
|---|---|
| Play | site.yml:105 |
| Tags | haproxy, keepalived, loadbalancer; each of the 38 per-service include_role … tasks_from: loadbalancer tasks in this play also carries its service tag |
| Play host patterns | loadbalancer |
| Node types in play (example inventory) | network |
| Node types running its containers | network |
| Containers | haproxy, proxysql, keepalived, haproxy_ssh |
deploy/reconfigure flow (tasks/) |
config-host → config → check-containers |
| Task files | check-containers.yml, check.yml, config-host.yml, config.yml, config_validate.yml, copy-certs.yml, deploy-containers.yml, deploy.yml, main.yml, precheck.yml, pull.yml, reconfigure.yml, stop.yml, upgrade.yml |
| Templates | haproxy-ssh/, haproxy-ssh/, haproxy/, haproxy/, haproxy/, haproxy/, keepalived/, keepalived/, keepalived/, keepalived/, proxysql/, proxysql/, proxysql/ |
| Handlers (definition order) | Check IP addresses on the API interface; Group HA nodes by status; Stop backup keepalived container; Stop backup haproxy container; Stop backup proxysql container; Start backup haproxy container; Wait for backup haproxy to start; Start backup proxysql container; Wait for backup proxysql to start; Start backup keepalived container; Stop master haproxy container; Stop master proxysql container; Stop master keepalived container; Start master haproxy container; Wait for master haproxy to start; Start master proxysql container; Wait for master proxysql to start; Start master keepalived container; Wait for haproxy to listen on VIP; Wait for proxysql to listen on VIP; Restart haproxy-ssh container |
| Key variables | enable_haproxy, enable_keepalived, kolla_internal_vip_address, kolla_external_vip_address, keepalived_virtual_router_id, kolla_enable_tls_* |
| Role dependencies | none |
Related¶
- Reconfigure a single service — a service tag renders the service's frontend;
in 2025.1 HAProxy picks it up only at the next
-t haproxyor untagged run - Tags §2.2 — handlers ignore tags; in 2025.1 nothing under
-t keystonenotifies the HAProxy handlers any more - Component dependencies §1 — every internal and public endpoint and the DB address resolve to the VIPs
- MariaDB/Galera — HAProxy sends DB traffic to one active backend
- Deployment execution flow — where the loadbalancer and letsencrypt plays run, and why the loadbalancer role flushes its handlers only at the end of its play
- Technical findings — F16, the first 2025.1 check of a
container whose unit 2024.1 wrote; F18,
-t <service>no longer restarts HAProxy - Pre-execution checklist — the checks before every production run
- Components — the other component pages