Skip to content

HAProxy snippets

HAProxy Load Balancer for k3s

This guide assumes you have a HAProxy load balancer setup to proxy traffic to your k3s cluster nodes. The load balancer will distribute incoming requests to the k3s API server across multiple master nodes, ensuring high availability.

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

defaults
    log     global
    mode    tcp
    option  tcplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000

frontend k3s-http
    bind 192.168.10.230:80
    default_backend k3s-http

frontend k3s-https
    bind 192.168.10.230:443
    default_backend k3s-https

frontend k3s-api
    bind 192.168.10.230:6443
    default_backend k3s-nodes

backend k3s-http
    balance roundrobin
    stick-table type ip size 200k expire 30m
    stick on src
    option tcp-check
    server node01 192.168.10.231:80 check
    server node02 192.168.10.232:80 check
    server node03 192.168.10.233:80 check

backend k3s-https
    balance roundrobin
    stick-table type ip size 200k expire 30m
    stick on src
    option tcp-check
    server node01 192.168.10.231:443 check
    server node02 192.168.10.232:443 check
    server node03 192.168.10.233:443 check

backend k3s-nodes
    balance roundrobin
    option tcp-check
    server node01 192.168.10.231:6443 check
    server node02 192.168.10.232:6443 check
    server node03 192.168.10.233:6443 check