From a28f9028a427ea2d0e928f7789c81334bf83a60d Mon Sep 17 00:00:00 2001 From: alecsandru Date: Sat, 4 May 2024 08:07:17 +0000 Subject: [PATCH] Update 'haproxy.yml' --- haproxy.yml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/haproxy.yml b/haproxy.yml index 847aa3d..c2ca435 100644 --- a/haproxy.yml +++ b/haproxy.yml @@ -26,10 +26,30 @@ copy: dest: /etc/keepalived/keepalived.conf content: "" + - name: Check APIServer Script + copy: + dest: /etc/keepalived/check_apiserver.sh + content: | + #!/bin/sh + errorExit() { + echo "*** $*" 1>&2 + exit 1 + } + curl --silent --max-time 2 --insecure https://localhost:{{ APISERVER_DEST_PORT }}/ -o /dev/null || errorExit "Error GET https://localhost:{{ APISERVER_DEST_PORT }}/" + if ip addr | grep -q {{ APISERVER_VIP }}; then + curl --silent --max-time 2 --insecure https://{{ APISERVER_VIP }}:{{ APISERVER_DEST_PORT }}/ -o /dev/null || errorExit "Error GET https://{{ APISERVER_VIP }}:{{ APISERVER_DEST_PORT }}/" + fi - name: Config keepalived blockinfile: dest: /etc/keepalived/keepalived.conf block: | + vrrp_script check_apiserver { + script "/etc/keepalived/check_apiserver.sh" + interval 3 + weight -2 + fall 10 + rise 2 + } vrrp_script chk_apiserver { script "/usr/bin/nc localhost 6443" interval 5 @@ -45,10 +65,10 @@ auth_pass 1111 } virtual_ipaddress { - 10.10.0.2 + {{ APISERVER_VIP }} } track_script { - chk_apiserver + check_apiserver } } vrrp_script chk_haproxy { @@ -66,7 +86,7 @@ auth_pass 2222 } virtual_ipaddress { - 10.10.0.3 + {{ ELB_VIP }} } track_script { chk_haproxy