mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2025-02-20 01:41:44 +01:00
Fix k3s_server_location only working on default
- K3s has some absolute paths set in various places which cannot be changed. Using a symbolic link was the easiest fix. This is nice for running K3S on SBC that must boot to SD but K3S data should be stored on a faster drive. - Other changes are for making the site playbook replayable without resetting the cluster. Ideally you can rerun it to check existing nodes or to add new ones. Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
parent
7cc70ad609
commit
8484c015d6
@ -58,8 +58,8 @@ ansible-playbook playbook/site.yml -i inventory.yml
|
||||
|
||||
## Kubeconfig
|
||||
|
||||
To get access to your **Kubernetes** cluster just
|
||||
To confirm access to your **Kubernetes** cluster use the following:
|
||||
|
||||
```bash
|
||||
scp debian@server_ip:~/.kube/config ~/.kube/config
|
||||
kubectl get nodes
|
||||
```
|
||||
|
@ -7,7 +7,7 @@
|
||||
systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server
|
||||
--cluster-init --tls-san {{ api_endpoint }} --data-dir {{ k3s_server_location }}
|
||||
{{ extra_server_args}}
|
||||
creates: "{{ systemd_dir }}/k3s-init.service"
|
||||
creates: "{{ k3s_server_location }}/server/node-token"
|
||||
when: groups['server'] | length > 1
|
||||
|
||||
- name: Start temporary service for single server cluster
|
||||
@ -15,7 +15,7 @@
|
||||
cmd: >
|
||||
systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server
|
||||
--tls-san {{ api_endpoint }} --data-dir {{ k3s_server_location }} {{ extra_server_args }}
|
||||
creates: "{{ systemd_dir }}/k3s-init.service"
|
||||
creates: "{{ k3s_server_location }}/server/node-token"
|
||||
when: groups['server'] | length == 1
|
||||
|
||||
- name: Wait for node-token
|
||||
@ -75,17 +75,17 @@
|
||||
flat: true
|
||||
when: ansible_hostname == groups['server'][0]
|
||||
|
||||
- name: Init additonal server nodes if any
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server
|
||||
--token "{{ hostvars[groups['server'][0]]['token'] }}" --server https://{{ api_endpoint }}:{{ api_port }}
|
||||
--tls-san {{ api_endpoint }} --data-dir {{ k3s_server_location }} {{ extra_server_args }}
|
||||
creates: "{{ systemd_dir }}/k3s-init.service"
|
||||
when: ansible_hostname != groups['server'][0]
|
||||
|
||||
- name: Verification and cleanup
|
||||
- name: Start other server if any and verify status
|
||||
block:
|
||||
- name: Init additonal server nodes
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
systemd-run -p RestartSec=2 -p Restart=on-failure --unit=k3s-init k3s server
|
||||
--token "{{ hostvars[groups['server'][0]]['token'] }}" --server https://{{ api_endpoint }}:{{ api_port }}
|
||||
--tls-san {{ api_endpoint }} --data-dir {{ k3s_server_location }} {{ extra_server_args }}
|
||||
creates: "{{ k3s_server_location }}/server/node-token"
|
||||
when: ansible_hostname != groups['server'][0]
|
||||
|
||||
- name: Verify that all server nodes joined
|
||||
ansible.builtin.command:
|
||||
cmd: k3s kubectl get nodes -l "node-role.kubernetes.io/control-plane=true" -o=jsonpath="{.items[*].metadata.name}"
|
||||
|
@ -52,3 +52,17 @@
|
||||
path: /etc/sudoers
|
||||
validate: 'visudo -cf %s'
|
||||
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat']
|
||||
|
||||
- name: Make k3s directory
|
||||
ansible.builtin.file:
|
||||
path: "/var/lib/rancher"
|
||||
mode: 0755
|
||||
state: directory
|
||||
|
||||
- name: Create symlink
|
||||
ansible.builtin.file:
|
||||
dest: /var/lib/rancher/k3s
|
||||
src: "{{ k3s_server_location }}"
|
||||
force: true
|
||||
state: link
|
||||
when: k3s_server_location != "/var/lib/rancher/k3s"
|
||||
|
@ -28,7 +28,7 @@
|
||||
- /run/k3s
|
||||
- /var/lib/kubelet
|
||||
- /run/netns
|
||||
- /var/lib/rancher/k3s
|
||||
- "{{ k3s_server_location }}"
|
||||
loop_control:
|
||||
loop_var: mounted_fs
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
- "{{ systemd_dir }}/k3s-agent.service"
|
||||
- /etc/rancher/k3s
|
||||
- /var/lib/kubelet
|
||||
- /var/lib/rancher/k3s
|
||||
- "{{ k3s_server_location }}"
|
||||
|
||||
- name: Systemd daemon reload
|
||||
|
Loading…
Reference in New Issue
Block a user