We need all machines up and running. At first we will setup the loadbalancer.
$ cat /etc/hosts
####################################################################
# IP FQDN ALIASES
#-------------- --------------------------- ------------------------
# Loadbalancer
<lb ip> <lb fqdn> <lb alias>
# K8s Server
<k8s server 1 ip> <k8s server 1 fqdn> CP_NODE_1 # <- We need the alias names in the nginx config
<k8s server 2 ip> <k8s server 1 fqdn> CP_NODE_2
<k8s server 3 ip> <k8s server 1 fqdn> CP_NODE_3
Now lets setup the nginx config:
user nginx;
worker_processes 4;
worker_rlimit_nofile 40000;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 8192;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
stream {
upstream backend {
least_conn;
server CP_NODE_1:9345 max_fails=3 fail_timeout=5s;
server CP_NODE_2:9345 max_fails=3 fail_timeout=5s;
#server CP_NODE_3:9345 max_fails=3 fail_timeout=5s;
}
# This server accepts all traffic to port 9345 and passes it to the upstream.
# Notice that the upstream name and the proxy_pass need to match.
server {
listen 9345;
proxy_pass backend;
}
upstream ef_cx_api {
least_conn;
server CP_NODE_1:6443 max_fails=3 fail_timeout=5s;
server CP_NODE_2:6443 max_fails=3 fail_timeout=5s;
#server CP_NODE_3:6443 max_fails=3 fail_timeout=5s;
}
server {
listen 6443;
proxy_pass ef_cx_api;
}
}
And (re)start the server systemctl restart nginx
.