Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Debian 10 - Set Up Nginx Load Balancer For Kubernetes

The tutorial below is how I set up my load balancer on Debian 10 for Kubernetes.

Related Posts

Resources

I deployed a VPS with 2 vCPUs and 512 MB of RAM.

Steps

Install Nginx

sudo apt update && sudo apt install nginx -y

Now replace your Nginx configuration using the command below. Be sure to change the IP addresses of the k3s_servers block as appropriate for your Kubernetes API servers.

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

events {}

stream {
    upstream k3s_servers {
        server 192.168.0.68:6443;
        server 192.168.0.69:6443;
        server 192.168.0.70:6443;
    }

    server {
        listen 6443;
        proxy_pass k3s_servers;
    }
}" | sudo tee /etc/nginx/nginx.conf

Reload Nginx:

sudo nginx -s reload

References

Last updated: 13th January 2025
First published: 23rd June 2021

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch