Added k3s agents
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
3
roles/helm/tasks/main.yml
Normal file
3
roles/helm/tasks/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
- include_tasks: installation.yml
|
||||
- include_tasks: apps.yml
|
||||
6
roles/k3s_agent/handlers/main.yml
Normal file
6
roles/k3s_agent/handlers/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Restart k3s
|
||||
service:
|
||||
name: k3s
|
||||
state: restarted
|
||||
become: yes
|
||||
21
roles/k3s_agent/tasks/installation.yml
Normal file
21
roles/k3s_agent/tasks/installation.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: See if k3s file exists
|
||||
stat:
|
||||
path: /usr/local/bin/k3s
|
||||
register: k3s_status
|
||||
|
||||
- name: Download K3s install script to /tmp/
|
||||
when: not k3s_status.stat.exists
|
||||
ansible.builtin.get_url:
|
||||
url: https://get.k3s.io
|
||||
dest: /tmp/k3s_install.sh
|
||||
mode: "0755"
|
||||
|
||||
- name: Install K3s on the secondary servers
|
||||
when: not k3s_status.stat.exists
|
||||
command: |
|
||||
/tmp/k3s_install.sh
|
||||
environment:
|
||||
K3S_URL: "https://{{ k3s.loadbalancer.ip }}:{{k3s.loadbalancer.default_port}}"
|
||||
K3S_TOKEN: "{{ k3s_token }}"
|
||||
become: true
|
||||
2
roles/k3s_agent/tasks/main.yml
Normal file
2
roles/k3s_agent/tasks/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- include_tasks: installation.yml
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
- name: Restart sshd
|
||||
- name: Restart k3s
|
||||
service:
|
||||
name: k3s
|
||||
state: restarted
|
||||
|
||||
@@ -1,32 +1,38 @@
|
||||
---
|
||||
# - name: Download K3s install script to /tmp/
|
||||
# ansible.builtin.get_url:
|
||||
# url: https://get.k3s.io
|
||||
# dest: /tmp/k3s_install.sh
|
||||
# mode: "0755"
|
||||
#
|
||||
# - name: Install K3s server with node taint and TLS SAN
|
||||
# when: host.ip == k3s.server.ips[0]
|
||||
# command: |
|
||||
# /tmp/k3s_install.sh server \
|
||||
# --node-taint CriticalAddonsOnly=true:NoExecute \
|
||||
# --tls-san {{ k3s.loadbalancer.ip }}
|
||||
# environment:
|
||||
# K3S_DATASTORE_ENDPOINT: "{{ k3s_db_connection_string }}"
|
||||
# become: true
|
||||
# async: 300
|
||||
# poll: 0
|
||||
# register: k3s_primary_install
|
||||
#
|
||||
# - name: Wait for K3s to be installed
|
||||
# when: host.ip == k3s.server.ips[0]
|
||||
# async_status:
|
||||
# jid: "{{ k3s_primary_install.ansible_job_id }}"
|
||||
# register: k3s_primary_install_status
|
||||
# until: k3s_primary_install_status.finished
|
||||
# retries: 60
|
||||
# delay: 5
|
||||
# become: true
|
||||
- name: See if k3s file exists
|
||||
stat:
|
||||
path: /usr/local/bin/k3s
|
||||
register: k3s_status
|
||||
|
||||
- name: Download K3s install script to /tmp/
|
||||
when: not k3s_status.stat.exists
|
||||
ansible.builtin.get_url:
|
||||
url: https://get.k3s.io
|
||||
dest: /tmp/k3s_install.sh
|
||||
mode: "0755"
|
||||
|
||||
- name: Install K3s server with node taint and TLS SAN
|
||||
when: (host.ip == k3s.server.ips[0] and (not k3s_status.stat.exists))
|
||||
command: |
|
||||
/tmp/k3s_install.sh server \
|
||||
--node-taint CriticalAddonsOnly=true:NoExecute \
|
||||
--tls-san {{ k3s.loadbalancer.ip }}
|
||||
environment:
|
||||
K3S_DATASTORE_ENDPOINT: "{{ k3s_db_connection_string }}"
|
||||
become: true
|
||||
async: 300
|
||||
poll: 0
|
||||
register: k3s_primary_install
|
||||
|
||||
- name: Wait for K3s to be installed
|
||||
when: (host.ip == k3s.server.ips[0] and (not k3s_status.stat.exists))
|
||||
async_status:
|
||||
jid: "{{ k3s_primary_install.ansible_job_id }}"
|
||||
register: k3s_primary_install_status
|
||||
until: k3s_primary_install_status.finished
|
||||
retries: 60
|
||||
delay: 5
|
||||
become: true
|
||||
|
||||
- name: Get K3s token from the first server
|
||||
when: host.ip == k3s.server.ips[0]
|
||||
@@ -39,16 +45,8 @@
|
||||
when: host.ip == k3s.server.ips[0]
|
||||
set_fact: k3s_token="{{ k3s_token['content'] | b64decode | trim }}"
|
||||
|
||||
- name: showdata
|
||||
when: host.ip != k3s.server.ips[0]
|
||||
debug:
|
||||
msg: "{{a}} {{k3s_datastore_endpoint}}"
|
||||
vars:
|
||||
k3s_datastore_endpoint: "{{ k3s_db_connection_string }}"
|
||||
a: "{{ hostvars[(hostvars | dict2items | map(attribute='value') | map('dict2items') | map('selectattr', 'key', 'match', 'host') | map('selectattr', 'value.ip', 'match', k3s.server.ips[0] ) | select() | first | items2dict).host.hostname].k3s_token }}"
|
||||
|
||||
- name: Install K3s on the secondary servers
|
||||
when: host.ip != k3s.server.ips[0]
|
||||
when: (host.ip != k3s.server.ips[0] and (not k3s_status.stat.exists))
|
||||
command: |
|
||||
/tmp/k3s_install.sh server \
|
||||
--node-taint CriticalAddonsOnly=true:NoExecute \
|
||||
|
||||
@@ -5,12 +5,12 @@ events {}
|
||||
stream {
|
||||
upstream k3s_servers {
|
||||
{% for ip in k3s_server_ips %}
|
||||
server {{ ip }}:6443;
|
||||
server {{ ip }}:{{k3s.loadbalancer.default_port}};
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 6443;
|
||||
listen {{k3s.loadbalancer.default_port}};
|
||||
proxy_pass k3s_servers;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user