Skip to content

Commit

Permalink
Fix k3s_server_location only working on default
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
bubylou authored and dereknola committed Nov 7, 2023
1 parent 97276c5 commit de7da1e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
24 changes: 12 additions & 12 deletions roles/k3s/server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
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
ansible.builtin.command:
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
Expand Down Expand Up @@ -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}"

Check failure on line 91 in roles/k3s/server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[line-length]

Line too long (122 > 120 characters)

Check warning on line 91 in roles/k3s/server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

91:121 [line-length] line too long (122 > 120 characters)
Expand Down
14 changes: 14 additions & 0 deletions roles/prereq/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion roles/reset/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- /run/k3s
- /var/lib/kubelet
- /run/netns
- /var/lib/rancher/k3s
- "{{ k3s_server_location }}"
loop_control:
loop_var: mounted_fs

Expand All @@ -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
Expand Down

0 comments on commit de7da1e

Please sign in to comment.