Add k3s ansible
This commit is contained in:
parent
d09ea3c0e0
commit
ecdcef3e02
5 changed files with 96 additions and 0 deletions
16
ansible/roles/k3s/tasks/clients.yml
Normal file
16
ansible/roles/k3s/tasks/clients.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- name: template k3s server systemd
|
||||
template:
|
||||
src: templates/k3s.service.j2
|
||||
dest: /etc/systemd/system/k3s.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: enable and start k3s
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
enabled: yes
|
||||
name: k3s
|
||||
state: started
|
||||
...
|
25
ansible/roles/k3s/tasks/get_k3s.yml
Normal file
25
ansible/roles/k3s/tasks/get_k3s.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- name: check k3s version
|
||||
shell:
|
||||
cmd: "k3s --version | grep k3s | cut -d' ' -f3"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
changed_when: False
|
||||
register: installed_k3s_version
|
||||
check_mode: False
|
||||
|
||||
- name: get k3s
|
||||
get_url:
|
||||
url: "https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64"
|
||||
dest: /usr/local/bin/k3s
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
when: installed_k3s_version.stdout != k3s_version
|
||||
|
||||
- name: link k3s
|
||||
file:
|
||||
src: /usr/local/bin/k3s
|
||||
dest: /usr/local/bin/kubernetes
|
||||
state: link
|
||||
...
|
7
ansible/roles/k3s/tasks/main.yml
Normal file
7
ansible/roles/k3s/tasks/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
- include: get_k3s.yml
|
||||
- include: server.yml
|
||||
when: k3s_role == "server"
|
||||
- include: clients.yml
|
||||
when: k3s_role == "client"
|
||||
...
|
25
ansible/roles/k3s/tasks/server.yml
Normal file
25
ansible/roles/k3s/tasks/server.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- name: template k3s server systemd
|
||||
template:
|
||||
src: templates/k3s.service.j2
|
||||
dest: /etc/systemd/system/k3s.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: enable and start k3s
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
enabled: yes
|
||||
name: k3s
|
||||
state: started
|
||||
|
||||
- name: get k3s token
|
||||
slurp:
|
||||
src: /var/lib/rancher/k3s/server/node-token
|
||||
register: registered_k3s_node_token
|
||||
|
||||
- name: set k3s token var
|
||||
set_fact:
|
||||
k3s_node_token: "{{ registered_k3s_node_token.content | b64decode | trim }}"
|
||||
...
|
23
ansible/roles/k3s/templates/k3s.service.j2
Normal file
23
ansible/roles/k3s/templates/k3s.service.j2
Normal file
|
@ -0,0 +1,23 @@
|
|||
[Unit]
|
||||
Description=k3s
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
{% if k3s_role == 'server' %}
|
||||
ExecStart=/usr/local/bin/k3s server --write-kubeconfig-mode 644 --disable servicelb --disable traefik
|
||||
{% else %}
|
||||
ExecStart=/usr/local/bin/k3s agent --server https://hardtack1.minhas.io:6443 --token {{ hostvars['hardtack1.minhas.io'].k3s_node_token }}
|
||||
{% endif %}
|
||||
KillMode=process
|
||||
KillSignal=SIGINT
|
||||
LimitNOFILE=infinity
|
||||
LimitNPROC=infinity
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
StartLimitBurst=3
|
||||
TasksMax=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue