From 22166acee16715c1cafe83c2669161e67458ba7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Karcewicz?= Date: Fri, 25 Mar 2022 23:14:25 +0100 Subject: [PATCH] MultiMaster_K3S_HA1 --- MultiMaster_K3S_HA/checkapi.sh | 11 +++++++++++ MultiMaster_K3S_HA/haproxy.cfg | 15 +++++++++++++++ MultiMaster_K3S_HA/keepalived.conf | 26 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 MultiMaster_K3S_HA/checkapi.sh create mode 100644 MultiMaster_K3S_HA/haproxy.cfg create mode 100644 MultiMaster_K3S_HA/keepalived.conf diff --git a/MultiMaster_K3S_HA/checkapi.sh b/MultiMaster_K3S_HA/checkapi.sh new file mode 100644 index 0000000..a4ae3d6 --- /dev/null +++ b/MultiMaster_K3S_HA/checkapi.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +errorExit() { + echo "*** $@" 1>&2 + exit 1 +} + +curl --silent --max-time 2 --insecure https://localhost:6443/ -o /dev/null || errorExit "Error GET https://localhost:6443/" +if ip addr | grep -q 192.168.101.111; then + curl --silent --max-time 2 --insecure https://192.168.101.111:6443/ -o /dev/null || errorExit "Error GET https://172.16.16.100:6443/" +fi diff --git a/MultiMaster_K3S_HA/haproxy.cfg b/MultiMaster_K3S_HA/haproxy.cfg new file mode 100644 index 0000000..c213179 --- /dev/null +++ b/MultiMaster_K3S_HA/haproxy.cfg @@ -0,0 +1,15 @@ +frontend kubernetes-frontend + bind *:6443 + mode tcp + option tcplog + default_backend kubernetes-backend + +backend kubernetes-backend + option httpchk GET /healthz + http-check expect status 200 + mode tcp + option ssl-hello-chk + balance roundrobin + server kmaster1 192.168.100.56:6443 check fall 3 rise 2 + server kmaster2 192.168.100.65:6443 check fall 3 rise 2 + server kmaster3 192.168.100.66:6443 check fall 3 rise 2 diff --git a/MultiMaster_K3S_HA/keepalived.conf b/MultiMaster_K3S_HA/keepalived.conf new file mode 100644 index 0000000..4407263 --- /dev/null +++ b/MultiMaster_K3S_HA/keepalived.conf @@ -0,0 +1,26 @@ +vrrp_script checkapi { + script "/etc/keepalived/checkapi.sh" + interval 2 # Uruchamiaj skrypt co 2 sekundy + timeout 5 # Poczekaj do 5 sekund na skrypt przed przyjęciem niezerowego kodu wyjścia + fall 3 # Jeśli skrypt zwraca kod niezerowy 3 razy z rzędu, wprowadź stan FAULT + rise 3 # Jeśli skrypt zwraca kod zero 3 razy z rzędu, wyjdź ze stanu FAULT + weight -10 # Zmniejsz priorytet o 10 przy wykrytej awarii +} + +vrrp_instance VI_1 { + state ACTIVE + interface enp0s3 + virtual_router_id 1 + priority 100 + advert_int 2 + authentication { + auth_type PASS + auth_pass mojehaslo + } + virtual_ipaddress { + 192.168.101.111 + } + track_script { + checkapi + } +}