diff --git a/ansible/roles/base/tasks/hardware.yml b/ansible/roles/base/tasks/hardware.yml index c8299bb..8afb535 100644 --- a/ansible/roles/base/tasks/hardware.yml +++ b/ansible/roles/base/tasks/hardware.yml @@ -2,8 +2,11 @@ - name: Deploy raspberry config template: - src: config.txt - dest: /boot/config.txt + src: "{{ item }}" + dest: /boot/{{ item }} + with_items: + - cmdline.txt + - config.txt notify: reboot - name: Set pi user in groups diff --git a/ansible/roles/base/templates/cmdline.txt b/ansible/roles/base/templates/cmdline.txt new file mode 100755 index 0000000..8c43902 --- /dev/null +++ b/ansible/roles/base/templates/cmdline.txt @@ -0,0 +1 @@ +console=serial0,115200 console=tty1 root=PARTUUID=424e930f-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory \ No newline at end of file diff --git a/ansible/roles/k3s/defaults/main.yml b/ansible/roles/k3s/defaults/main.yml new file mode 100644 index 0000000..7b9ca3a --- /dev/null +++ b/ansible/roles/k3s/defaults/main.yml @@ -0,0 +1,3 @@ +--- +k3s_version: v1.19.15%2Bk3s2 +k3s_url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-{{ arch | default('armhf') }} diff --git a/ansible/roles/k3s/handlers/main.yml b/ansible/roles/k3s/handlers/main.yml new file mode 100644 index 0000000..315eae8 --- /dev/null +++ b/ansible/roles/k3s/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart k3s + systemd: + name: k3s + enabled: yes + daemon_reload: yes + state: restarted diff --git a/ansible/roles/k3s/tasks/containerd.yml b/ansible/roles/k3s/tasks/containerd.yml new file mode 100644 index 0000000..54812ec --- /dev/null +++ b/ansible/roles/k3s/tasks/containerd.yml @@ -0,0 +1,18 @@ +- name: Add apt key + apt_key: + url: https://download.docker.com/linux/debian/gpg + +- name: Add docker-ce repository + apt_repository: + repo: deb [arch={{ arch | default('armhf') }}] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable + state: present + filename: 'docker' + + +- meta: flush_handlers + +- name: Install containerd.io + apt: + name: + - containerd.io + state: present diff --git a/ansible/roles/k3s/tasks/k3s.yml b/ansible/roles/k3s/tasks/k3s.yml new file mode 100644 index 0000000..6e2f4c8 --- /dev/null +++ b/ansible/roles/k3s/tasks/k3s.yml @@ -0,0 +1,20 @@ +--- +- name: Download k3s binary + get_url: + url: "{{ k3s_url}}" + dest: "/usr/local/bin/k3s" + mode: 0755 + force: yes + +- name: Copy systemd script + template: + src: k3s.service.j2 + dest: /etc/systemd/system/k3s.service + notify: restart k3s + +- name: Ensure k3s service is started + systemd: + name: k3s + enabled: yes + daemon_reload: yes + state: started diff --git a/ansible/roles/k3s/tasks/main.yaml b/ansible/roles/k3s/tasks/main.yaml new file mode 100644 index 0000000..b1fb458 --- /dev/null +++ b/ansible/roles/k3s/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include_tasks: containerd.yml +- include_tasks: k3s.yml diff --git a/ansible/roles/k3s/templates/k3s.service.j2 b/ansible/roles/k3s/templates/k3s.service.j2 new file mode 100644 index 0000000..dd971e6 --- /dev/null +++ b/ansible/roles/k3s/templates/k3s.service.j2 @@ -0,0 +1,29 @@ +[Unit] +Description=Lightweight Kubernetes +Documentation=https://k3s.io +Wants=network-online.target,containerd +After=network-online.target,containerd + +[Install] +WantedBy=multi-user.target + +[Service] +Type=notify +EnvironmentFile=-/etc/default/%N +EnvironmentFile=-/etc/sysconfig/%N +EnvironmentFile=-/etc/k3s/conf.env +KillMode=process +Delegate=yes +# Having non-zero Limit*s causes performance problems due to accounting overhead +# in the kernel. We recommend using cgroups to do container-local accounting. +LimitNOFILE=1048576 +LimitNPROC=infinity +LimitCORE=infinity +TasksMax=infinity +TimeoutStartSec=0 +Restart=always +RestartSec=5s +ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service' +ExecStartPre=-/sbin/modprobe br_netfilter +ExecStartPre=-/sbin/modprobe overlay +ExecStart=/usr/local/bin/k3s server diff --git a/ansible/site.yml b/ansible/site.yml index bdd825f..6ba0463 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -9,7 +9,7 @@ become: yes roles: - { role: rabbitmq, tags: [rabbitmq] } - - { role: docker, tags: [docker] } + - { role: k3s, tags: [k3s] } - { role: microservices, tags: [microservices, ms] }