Skip to content

Nginx cluster load balancer

Nginx can be used to load balance traffic into a k3s cluster with a ingress nginx nodeport configuration. The ingress listens for http and https traffic on specified ports on all cluster nodes. The incoming http and https traffics gets send to the cluster via a nginx proxy.

Example nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    upstream cluster-http {
                server 192.168.192.101:32412 max_fails=2 fail_timeout=60s;
                server 192.168.192.102:32412 max_fails=2 fail_timeout=60s;
                server 192.168.192.103:32412 max_fails=2 fail_timeout=60s;
            }

    server {
        listen 80 default_server;

        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Real-IP $remote_addr;

            proxy_pass http://cluster-http;
        }
    }

}


stream {

    upstream cluster-https {
                server 192.168.192.101:32413 max_fails=2 fail_timeout=60s;
                server 192.168.192.102:32413 max_fails=2 fail_timeout=60s;
                server 192.168.192.103:32413 max_fails=2 fail_timeout=60s;
            }

    server {
        listen 443;
        proxy_pass cluster-https;
    }
}
Back to top