diff --git a/Dockerfile b/Dockerfile index cb5937d..1cf6b0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,9 @@ RUN apk add --no-cache \ && adduser -S -s /sbin/nologin -G keepalived_script -H keepalived_script COPY keepalived.conf /etc/keepalived/keepalived.conf +COPY check_apiserver.sh /etc/keepalived/check_apiserver.sh COPY init.sh / -RUN chmod +x /init.sh + +RUN chmod +x /init.sh && chmod +x /etc/keepalived/check_apiserver.sh + CMD ["/init.sh"] diff --git a/Makefile b/Makefile index 0b09dac..47edd7e 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ shell_build_image = $(OCI_CLI_BUILD) build --platform $(PLATFORM) -t $(REGISTRY_ $(OCI_CLI) push $(REGISTRY_IP):5000/$(1); imageKeepalived: - $(call shell_build_image,keepalived) + $(call shell_build_image,keepalived-k8s) ## management diff --git a/check_apiserver.sh b/check_apiserver.sh new file mode 100644 index 0000000..c2bcc5b --- /dev/null +++ b/check_apiserver.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 100.105.163.74; then + curl --silent --max-time 2 --insecure https://100.105.163.74:6443/ -o /dev/null || errorExit "Error GET https://100.105.163.74:6443/" +fi \ No newline at end of file diff --git a/keepalived.conf b/keepalived.conf index 23e7cdc..580c060 100644 --- a/keepalived.conf +++ b/keepalived.conf @@ -3,7 +3,7 @@ global_defs { } vrrp_script chk_kube { - script /usr/bin/curl --silent --max-time 2 --insecure https://100.105.163.74:6443/ -o /dev/null || echo "*** Error GET https://100.105.163.74:6443/" 1>&2 && exit 1 + script "/etc/keepalived/check_apiserver.sh" interval 2 # check every 2 seconds weight 2 # add n points of prio if OK }