Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set tags for load balancers #613

Merged
merged 4 commits into from
Mar 28, 2024
Merged

Conversation

vitabaks
Copy link
Owner

@vitabaks vitabaks commented Mar 28, 2024

Variable: balancer_tags

Example (/etc/haproxy/haproxy.cfg ):

global
    maxconn 100000
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

defaults
    mode               tcp
    log                global
    retries            2
    timeout queue      5s
    timeout connect    5s
    timeout client     60m
    timeout server     60m
    timeout check      15s

listen stats
    mode http
    bind 10.172.0.20:7000
    stats enable
    stats uri /

listen master
    bind 10.172.0.20:5000
    maxconn 10000
    option tcplog
    option httpchk OPTIONS /primary
    http-check expect status 200
    default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions
 server pgnode01 10.172.0.20:6432 check port 8008
 server pgnode02 10.172.0.21:6432 check port 8008
 server pgnode03 10.172.0.22:6432 check port 8008


listen replicas
    bind 10.172.0.20:5001
    maxconn 10000
    option tcplog
    option httpchk OPTIONS /replica?lag=100MB&tag_datacenter=dc1
    balance roundrobin
    http-check expect status 200
    default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
 server pgnode01 10.172.0.20:6432 check port 8008
 server pgnode02 10.172.0.21:6432 check port 8008
 server pgnode03 10.172.0.22:6432 check port 8008


listen replicas_sync
    bind 10.172.0.20:5002
    maxconn 10000
    option tcplog
    option httpchk OPTIONS /sync?tag_datacenter=dc1
    balance roundrobin
    http-check expect status 200
    default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
 server pgnode01 10.172.0.20:6432 check port 8008
 server pgnode02 10.172.0.21:6432 check port 8008
 server pgnode03 10.172.0.22:6432 check port 8008


listen replicas_async
    bind 10.172.0.20:5003
    maxconn 10000
    option tcplog
    option httpchk OPTIONS /async?lag=100MB&tag_datacenter=dc1
    balance roundrobin
    http-check expect status 200
    default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
 server pgnode01 10.172.0.20:6432 check port 8008
 server pgnode02 10.172.0.21:6432 check port 8008
 server pgnode03 10.172.0.22:6432 check port 8008

To separate load balancers across different data centers

  1. To separate load balancers across different data centers (each has its VIP), just create separate inventory files (e.q. cluster.hosts, balancers_dc1.hosts, balancers_dc2.hosts). See an example here
  2. To separate the read-only traffic across different data centers, add the datacenter=<name> tag to the ‘patroni_tags’ and ‘balancer_tags’ variables in the inventory for the respective hosts. See an example here

@vitabaks vitabaks added enhancement New feature or request sponsor's request labels Mar 28, 2024
@vitabaks vitabaks self-assigned this Mar 28, 2024
@vitabaks vitabaks merged commit 1a5eeb5 into master Mar 28, 2024
17 checks passed
@vitabaks vitabaks deleted the balancer-tags branch March 28, 2024 10:31
christofalpo pushed a commit to christofalpo/postgresql_cluster that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sponsor's request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant