Skip to content

Commit e7c3373

Browse files
committed
chore(examples/config/rke2): Add full RKE2 cluter example with HAProxy
1 parent a1cf09f commit e7c3373

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
meta:
2+
schema_version: 3
3+
global:
4+
vars:
5+
token: o94defesf8pezm560xghrjsgt7nii2hx
6+
server: gobble-example-rke2-ma1.sikademo.com
7+
hosts:
8+
proxy:
9+
- ssh_target: root@gobble-example-rke2-proxy.sikademo.com
10+
ma:
11+
- ssh_target: root@gobble-example-rke2-ma1.sikademo.com
12+
vars:
13+
first_master: true
14+
- ssh_target: root@gobble-example-rke2-ma2.sikademo.com
15+
- ssh_target: root@gobble-example-rke2-ma3.sikademo.com
16+
wo:
17+
- ssh_target: root@gobble-example-rke2-wo1.sikademo.com
18+
vars:
19+
backend: gobble-example-rke2-wo1.sikademo.com
20+
- ssh_target: root@gobble-example-rke2-wo2.sikademo.com
21+
vars:
22+
backend: gobble-example-rke2-wo2.sikademo.com
23+
- ssh_target: root@gobble-example-rke2-wo3.sikademo.com
24+
vars:
25+
backend: gobble-example-rke2-wo3.sikademo.com
26+
plays:
27+
- name: Install Requirements & Commons
28+
hosts: [proxy, ma, wo]
29+
tags: [install]
30+
tasks:
31+
- name: Install apt requirements
32+
command:
33+
cmd: apt update && apt install -y curl git open-iscsi nfs-common
34+
35+
- name: Install slu
36+
command:
37+
cmd: curl -fsSL https://raw.githubusercontent.com/sikalabs/slu/master/install.sh | sh
38+
39+
- name: Install kubectl (using slu)
40+
command:
41+
cmd: slu install-bin kubectl
42+
43+
- name: Install helm (using slu)
44+
command:
45+
cmd: slu install-bin helm
46+
47+
- name: Setup Master Nodes
48+
hosts: [ma]
49+
tags: [master]
50+
tasks:
51+
- name: Create /etc/rancher/rke2 dir
52+
command:
53+
cmd: mkdir -p /etc/rancher/rke2
54+
55+
- name: Create /etc/rancher/rke2/config.yaml
56+
template:
57+
path: /etc/rancher/rke2/config.yaml
58+
template: |
59+
{{ if not .Vars.first_master }}
60+
server: https://{{.Vars.server}}:9345
61+
{{ end }}
62+
token: {{.Vars.token}}
63+
node-taint:
64+
- "CriticalAddonsOnly=true:NoExecute"
65+
disable:
66+
- rke2-ingress-nginx
67+
68+
- name: Install RKE2
69+
command:
70+
cmd: curl -sfL https://get.rke2.io | INSTALL_RKE2_METHOD='tar' sh -
71+
72+
- name: Enable RKE2
73+
command:
74+
cmd: systemctl enable rke2-server.service
75+
76+
- name: Start RKE2
77+
command:
78+
cmd: systemctl start rke2-server.service
79+
80+
- name: Create ~/.kube dir
81+
command:
82+
cmd: mkdir -p /root/.kube
83+
84+
- name: Create ~/.kube/config
85+
command:
86+
cmd: rm -rf /root/.kube/config && ln -s /etc/rancher/rke2/rke2.yaml /root/.kube/config
87+
88+
- name: Try it!
89+
print:
90+
template: |
91+
ssh root@gobble-example-rke2-simple-node.sikademo.com kubectl get nodes
92+
93+
- name: Setup Worker Nodes
94+
hosts: [wo]
95+
tags: [worker]
96+
tasks:
97+
- name: Create /etc/rancher/rke2 dir
98+
command:
99+
cmd: mkdir -p /etc/rancher/rke2
100+
101+
- name: Create /etc/rancher/rke2/config.yaml
102+
template:
103+
path: /etc/rancher/rke2/config.yaml
104+
template: |
105+
server: https://{{.Vars.server}}:9345
106+
token: {{.Vars.token}}
107+
108+
- name: Install RKE2
109+
command:
110+
cmd: curl -sfL https://get.rke2.io | INSTALL_RKE2_METHOD='tar' sh -
111+
112+
- name: Install RKE2
113+
command:
114+
cmd: curl -sfL https://get.rke2.io | INSTALL_RKE2_METHOD='tar' INSTALL_RKE2_TYPE=agent sh -
115+
116+
- name: Enable RKE2
117+
command:
118+
cmd: systemctl enable rke2-agent.service
119+
120+
- name: Start RKE2
121+
command:
122+
cmd: systemctl start rke2-agent.service
123+
124+
- name: Proxy
125+
hosts: [proxy]
126+
tags: [proxy]
127+
tasks:
128+
- name: Install HAProxy
129+
apt_install:
130+
name: haproxy
131+
132+
- name: Config HAProxy
133+
template:
134+
path: /etc/haproxy/haproxy.cfg
135+
template: |
136+
defaults
137+
mode tcp
138+
timeout client 10s
139+
timeout connect 5s
140+
timeout server 10s
141+
timeout http-request 10s
142+
143+
frontend http
144+
bind 0.0.0.0:80
145+
default_backend http
146+
147+
frontend https
148+
bind 0.0.0.0:443
149+
default_backend https
150+
151+
backend http
152+
{{ range $i, $server := .Config.Hosts.wo }}
153+
server backend-http-{{$i}} {{$server.Vars.backend}}:80
154+
{{ end }}
155+
156+
backend https
157+
{{ range $i, $server := .Config.Hosts.wo }}
158+
server backend-https-{{$i}} {{$server.Vars.backend}}:443
159+
{{ end }}
160+
161+
- name: Restart HAProxy
162+
command:
163+
cmd: service haproxy restart
164+
165+
- name: Setup Workload
166+
hosts: [ma]
167+
tags: [workload]
168+
tasks:
169+
- name: Install Cluster Essentials (ingress-nginx, cert-manager, cluster issuer)
170+
command:
171+
cmd: slu scripts kubernetes install-all --base-domain gobble-example-rke2-proxy.sikademo.com --no-argocd
172+
173+
- name: Install Hello World App
174+
command:
175+
cmd: slu scripts kubernetes install-hello-world --host gobble-example-rke2-proxy.sikademo.com --replicas 3
176+
177+
- name: Wait for valit TLS certificate
178+
command:
179+
cmd: slu wait-for tls -a gobble-example-rke2-proxy.sikademo.com:443
180+
181+
- name: Try it!
182+
print:
183+
template: |
184+
See: https://gobble-example-rke2-proxy.sikademo.com

examples/config/rke2/uninstall.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
meta:
2+
schema_version: 3
3+
hosts:
4+
nodes:
5+
- ssh_target: root@gobble-example-rke2-ma1.sikademo.com
6+
- ssh_target: root@gobble-example-rke2-ma2.sikademo.com
7+
- ssh_target: root@gobble-example-rke2-ma3.sikademo.com
8+
- ssh_target: root@gobble-example-rke2-wo1.sikademo.com
9+
- ssh_target: root@gobble-example-rke2-wo2.sikademo.com
10+
- ssh_target: root@gobble-example-rke2-wo3.sikademo.com
11+
plays:
12+
- name: Uninstall RKE2
13+
hosts: [nodes]
14+
tasks:
15+
- name: Uninstall RKE2
16+
command:
17+
cmd: /usr/local/bin/rke2-uninstall.sh || true

0 commit comments

Comments
 (0)