diff --git a/tasks/load_balancer.yml b/tasks/load_balancer.yml index 5fbe33c..c9ac070 100644 --- a/tasks/load_balancer.yml +++ b/tasks/load_balancer.yml @@ -19,7 +19,7 @@ with_items: - { lbip: '{{ lbip_kubeapiserver }}', state: "MASTER", interface: '{{ lb_interface }}', auth_pass: '{{ lb_auth_pass }}' } when: - - groups['Kube-masters'][0] == ansible_hostname + - groups['KubernetesMasters'][0] == ansible_hostname notify: Restart keepalived - name: Install keepalived config file template: @@ -28,5 +28,5 @@ with_items: - { lbip: '{{ lbip_kubeapiserver }}', state: "BACKUP", interface: '{{ lb_interface }}', auth_pass: '{{ lb_auth_pass }}' } when: - - not groups['Kube-masters'][0] == ansible_hostname + - not groups['KubernetesMasters'][0] == ansible_hostname notify: Restart keepalived diff --git a/templates/etc/keepalived/check_apiserver.sh.j2 b/templates/etc/keepalived/check_apiserver.sh.j2 new file mode 100644 index 0000000..e02032e --- /dev/null +++ b/templates/etc/keepalived/check_apiserver.sh.j2 @@ -0,0 +1,12 @@ +#!/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 {{ lbip_kubeapiserver }}; then + curl --silent --max-time 2 --insecure https://{{ lbip_kubeapiserver }}:6443/ -o /dev/null || errorExit "Error GET https://{{ lbip_kubeapiserver }}:6443/" +fi + diff --git a/templates/etc/keepalived/keepalived.conf.j2 b/templates/etc/keepalived/keepalived.conf.j2 new file mode 100644 index 0000000..b1fd9b9 --- /dev/null +++ b/templates/etc/keepalived/keepalived.conf.j2 @@ -0,0 +1,33 @@ +! Configuration File for keepalived +global_defs { + router_id LVS_DEVEL +} + +vrrp_script check_apiserver { + script "/etc/keepalived/check_apiserver.sh" + interval 3 + weight -2 + fall 10 + rise 2 +} + +vrrp_instance VI_1 { + state {{ item.state }} + interface {{ item.interface }} + virtual_router_id 51 +{% if item.state == "MASTER" %} + priority 101 +{% elif item.state == "BACKUP" %} + priority 100 +{% endif %} + authentication { + auth_type PASS + auth_pass {{ item.auth_pass }} + } + virtual_ipaddress { + {{ item.lbip }} + } + track_script { + check_apiserver + } +} \ No newline at end of file