From d22ad01d507498e8fd78cd19ddd42ad92b0b750c Mon Sep 17 00:00:00 2001 From: Jiayi Hu Date: Tue, 15 Dec 2020 00:24:20 +0100 Subject: [PATCH] Add Alpine Linux configuration Signed-off-by: Jiayi Hu --- roles/k3s/master/tasks/main.yml | 22 +++++------------ roles/k3s/master/tasks/prereq/Alpine.yml | 30 +++++++++++++++++++++++ roles/k3s/master/tasks/prereq/default.yml | 16 ++++++++++++ roles/k3s/node/tasks/main.yml | 19 ++++---------- roles/k3s/node/tasks/prereq/Alpine.yml | 30 +++++++++++++++++++++++ roles/k3s/node/tasks/prereq/default.yml | 15 ++++++++++++ roles/raspberrypi/handlers/main.yml | 4 +++ roles/raspberrypi/tasks/prereq/Alpine.yml | 29 ++++++++++++++++++++++ 8 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 roles/k3s/master/tasks/prereq/Alpine.yml create mode 100644 roles/k3s/master/tasks/prereq/default.yml create mode 100644 roles/k3s/node/tasks/prereq/Alpine.yml create mode 100644 roles/k3s/node/tasks/prereq/default.yml create mode 100644 roles/raspberrypi/tasks/prereq/Alpine.yml diff --git a/roles/k3s/master/tasks/main.yml b/roles/k3s/master/tasks/main.yml index 006aa9b..cf3889b 100644 --- a/roles/k3s/master/tasks/main.yml +++ b/roles/k3s/master/tasks/main.yml @@ -1,20 +1,10 @@ --- -- name: Copy K3s service file - register: k3s_service - template: - src: "k3s.service.j2" - dest: "{{ systemd_dir }}/k3s.service" - owner: root - group: root - mode: 0755 - -- name: Enable and check K3s service - systemd: - name: k3s - daemon_reload: yes - state: restarted - enabled: yes +- name: Create and enable K3s service + include_tasks: "{{ item }}" + with_first_found: + - "prereq/{{ ansible_distribution }}.yml" + - "prereq/default.yml" - name: Wait for node-token wait_for: @@ -61,7 +51,7 @@ - name: Replace https://localhost:6443 by https://master-ip:6443 command: >- - k3s kubectl config set-cluster default + /usr/local/bin/k3s kubectl config set-cluster default --server=https://{{ master_ip }}:6443 --kubeconfig ~{{ ansible_user }}/.kube/config changed_when: true diff --git a/roles/k3s/master/tasks/prereq/Alpine.yml b/roles/k3s/master/tasks/prereq/Alpine.yml new file mode 100644 index 0000000..76b3d73 --- /dev/null +++ b/roles/k3s/master/tasks/prereq/Alpine.yml @@ -0,0 +1,30 @@ +--- +- name: Copy K3s service file + register: k3s_service + copy: + content: | + #!/sbin/openrc-run + + name="k3s server" + command="/usr/local/bin/k3s" + command_args="server {{ extra_server_args | default("") }}" + command_background=true + pidfile="/run/${RC_SVCNAME}.pid" + output_log="/var/log/k3s.log" + error_log="/var/log/k3s.err" + dest: /etc/init.d/k3s + owner: root + group: root + mode: 0755 + +- name: Create K3s service symlink + file: + src: /etc/init.d/k3s + dest: /etc/runlevels/default/k3s + state: link + +- name: Enable and check K3s service + service: + name: k3s + state: restarted + enabled: yes diff --git a/roles/k3s/master/tasks/prereq/default.yml b/roles/k3s/master/tasks/prereq/default.yml new file mode 100644 index 0000000..eca0868 --- /dev/null +++ b/roles/k3s/master/tasks/prereq/default.yml @@ -0,0 +1,16 @@ +--- +- name: Copy K3s service file + register: k3s_service + template: + src: "k3s.service.j2" + dest: "{{ systemd_dir }}/k3s.service" + owner: root + group: root + mode: 0755 + +- name: Enable and check K3s service + systemd: + name: k3s + daemon_reload: yes + state: restarted + enabled: yes diff --git a/roles/k3s/node/tasks/main.yml b/roles/k3s/node/tasks/main.yml index 0ce8e08..50abd6c 100644 --- a/roles/k3s/node/tasks/main.yml +++ b/roles/k3s/node/tasks/main.yml @@ -1,16 +1,7 @@ --- -- name: Copy K3s service file - template: - src: "k3s.service.j2" - dest: "{{ systemd_dir }}/k3s-node.service" - owner: root - group: root - mode: 0755 - -- name: Enable and check K3s service - systemd: - name: k3s-node - daemon_reload: yes - state: restarted - enabled: yes +- name: Create and enable K3s service + include_tasks: "{{ item }}" + with_first_found: + - "prereq/{{ ansible_distribution }}.yml" + - "prereq/default.yml" diff --git a/roles/k3s/node/tasks/prereq/Alpine.yml b/roles/k3s/node/tasks/prereq/Alpine.yml new file mode 100644 index 0000000..5c94907 --- /dev/null +++ b/roles/k3s/node/tasks/prereq/Alpine.yml @@ -0,0 +1,30 @@ +--- +- name: Copy K3s service file + register: k3s_service + copy: + content: | + #!/sbin/openrc-run + + name="k3s agent" + command="/usr/local/bin/k3s" + command_args="agent --server https://{{ master_ip }}:6443 --token {{ hostvars[groups['master'][0]]['token'] }} {{ extra_agent_args | default("") }}" + command_background=true + pidfile="/run/${RC_SVCNAME}.pid" + output_log="/var/log/k3s.log" + error_log="/var/log/k3s.err" + dest: /etc/init.d/k3s + owner: root + group: root + mode: 0755 + +- name: Create K3s service symlink + file: + src: /etc/init.d/k3s + dest: /etc/runlevels/default/k3s + state: link + +- name: Enable and check K3s service + service: + name: k3s + state: restarted + enabled: yes diff --git a/roles/k3s/node/tasks/prereq/default.yml b/roles/k3s/node/tasks/prereq/default.yml new file mode 100644 index 0000000..64050cf --- /dev/null +++ b/roles/k3s/node/tasks/prereq/default.yml @@ -0,0 +1,15 @@ +--- +- name: Copy K3s service file + template: + src: "k3s.service.j2" + dest: "{{ systemd_dir }}/k3s-node.service" + owner: root + group: root + mode: 0755 + +- name: Enable and check K3s service + systemd: + name: k3s-node + daemon_reload: yes + state: restarted + enabled: yes diff --git a/roles/raspberrypi/handlers/main.yml b/roles/raspberrypi/handlers/main.yml index d25cf90..ddbdadf 100644 --- a/roles/raspberrypi/handlers/main.yml +++ b/roles/raspberrypi/handlers/main.yml @@ -1,3 +1,7 @@ --- - name: reboot reboot: + +- name: lbu + debug: + msg: If you are diskless on Alpine you should commit changes with 'lbu -u' now and reboot. diff --git a/roles/raspberrypi/tasks/prereq/Alpine.yml b/roles/raspberrypi/tasks/prereq/Alpine.yml new file mode 100644 index 0000000..ae056a2 --- /dev/null +++ b/roles/raspberrypi/tasks/prereq/Alpine.yml @@ -0,0 +1,29 @@ +--- +- name: Add cgroup mount point + lineinfile: + path: /etc/fstab + line: cgroup /sys/fs/cgroup cgroup defaults 0 0 + +- name: Define cgroup mount points + copy: + content: | + mount { + cpuacct = /cgroup/cpuacct; + memory = /cgroup/memory; + devices = /cgroup/devices; + freezer = /cgroup/freezer; + net_cls = /cgroup/net_cls; + blkio = /cgroup/blkio; + cpuset = /cgroup/cpuset; + cpu = /cgroup/cpu; + } + dest: /etc/cgconfig.conf + mode: 0644 + +- name: Enable cgroup via boot commandline if not already enabled + lineinfile: + path: /media/mmcblk0p1/cmdline.txt + backrefs: yes + regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' + line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' + notify: lbu