Commit 8484c015 authored by Nicholas Malcolm's avatar Nicholas Malcolm Committed by Derek Nola
Browse files

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: default avatarDerek Nola <derek.nola@suse.com>
parent 7cc70ad6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
```
+12 −12
Original line number Diff line number Diff line
@@ -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
- 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: "{{ systemd_dir }}/k3s-init.service"
        creates: "{{ k3s_server_location }}/server/node-token"
      when: ansible_hostname != groups['server'][0]

- name: Verification and cleanup
  block:
    - 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}"
+14 −0
Original line number Diff line number Diff line
@@ -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"
+2 −1
Original line number Diff line number Diff line
@@ -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