#!/bin/bash #Instalacion de Loadbalancer simple. hostname kublb01 cat < /etc/hostname kublb01 EOF # Add ip y nombres de hosts en todos los masters cat <> /etc/hosts 172.31.27.31 kub01 172.31.41.254 kub02 172.31.12.35 kub03 172.31.12.10 kublb01 172.31.12.20 minion1 172.31.12.21 minion2 EOF apt-get update apt-get install nginx nginx-extras -y cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak cat <<__EOF__>/etc/nginx/nginx.conf worker_processes 1; include /etc/nginx/modules-enabled/*.conf; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } stream { upstream apiserver { server 172.31.27.31:6443 weight=5 max_fails=3 fail_timeout=03s; server 172.31.41.254:6443 weight=5 max_fails=3 fail_timeout=03s; server 172.31.12.35:6443 weight=5 max_fails=3 fail_timeout=03s; #server ${HOST_IP}:6443 weight=5 max_fails=3 fail_timeout=30s; #server ${HOST_IP}:6443 weight=5 max_fails=3 fail_timeout=30s; } server { listen 6443; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass apiserver; } } __EOF__ systemctl restart nginx && systemctl status nginx && systemctl enable nginx