forked from tranductrinh/k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlb_playbook.yml
122 lines (106 loc) · 3.08 KB
/
lb_playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
- hosts: lbs
name: Setup load balancers
remote_user: ci
become: yes
tasks:
- name: Install haproxy
apt:
name:
- haproxy
state: present
update_cache: yes
- name: Create haproxy conf empty file
copy:
content: ""
dest: /etc/haproxy/haproxy.cfg
force: yes
- name: Configure haproxy
shell: |
cat <<EOF | sudo tee /etc/haproxy/haproxy.cfg
frontend kube_apiserver_frontend
bind *:6443
mode tcp
option tcplog
default_backend kube_apiserver_backend
backend kube_apiserver_backend
option httpchk GET /healthz
http-check expect status 200
mode tcp
option ssl-hello-chk
balance roundrobin
server k8s-master-1 172.16.1.11:6443 check fall 3 rise 2
server k8s-master-2 172.16.1.12:6443 check fall 3 rise 2
server k8s-master-3 172.16.1.13:6443 check fall 3 rise 2
frontend http_frontend
bind *:80
mode tcp
option tcplog
default_backend http_backend
backend http_backend
mode tcp
balance roundrobin
server k8s-worker-1 172.16.2.11:30100 check send-proxy-v2
server k8s-worker-2 172.16.2.12:30100 check send-proxy-v2
server k8s-worker-3 172.16.2.13:30100 check send-proxy-v2
frontend https_frontend
bind *:443
mode tcp
option tcplog
default_backend https_backend
backend https_backend
mode tcp
balance roundrobin
server k8s-worker-1 172.16.2.11:30101 check send-proxy-v2
server k8s-worker-2 172.16.2.12:30101 check send-proxy-v2
server k8s-worker-3 172.16.2.13:30101 check send-proxy-v2
EOF
- name: Restart haproxy
systemd:
name: haproxy
state: restarted
enabled: yes
daemon-reload: yes
- name: Install keepalived
apt:
name:
- keepalived
state: present
update_cache: yes
- name: Create keepalived.conf empty file
copy:
content: ""
dest: /etc/keepalived/keepalived.conf
force: yes
- name: Create keepalived.conf
blockinfile:
path: /etc/keepalived/keepalived.conf
block: |
vrrp_script check_apiserver {
script "killall -0 haproxy"
interval 3
timeout 10
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 201
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass secret
}
virtual_ipaddress {
{{ cluster_vip }}/24
}
track_script {
check_apiserver
}
}
- name: Restart keepalived
systemd:
name: keepalived
state: restarted
enabled: yes
daemon-reload: yes