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.

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: 24th June 2021
First published: 23rd June 2021