refactor: replace docker stack with k3s/containerd

This commit is contained in:
Cyrille Nofficial 2022-01-02 17:30:56 +01:00
parent 7dd4c118c8
commit 2fccdd0283
9 changed files with 87 additions and 3 deletions

View File

@ -2,8 +2,11 @@
- name: Deploy raspberry config - name: Deploy raspberry config
template: template:
src: config.txt src: "{{ item }}"
dest: /boot/config.txt dest: /boot/{{ item }}
with_items:
- cmdline.txt
- config.txt
notify: reboot notify: reboot
- name: Set pi user in groups - name: Set pi user in groups

View File

@ -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

View File

@ -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') }}

View File

@ -0,0 +1,7 @@
---
- name: restart k3s
systemd:
name: k3s
enabled: yes
daemon_reload: yes
state: restarted

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
---
- include_tasks: containerd.yml
- include_tasks: k3s.yml

View File

@ -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

View File

@ -9,7 +9,7 @@
become: yes become: yes
roles: roles:
- { role: rabbitmq, tags: [rabbitmq] } - { role: rabbitmq, tags: [rabbitmq] }
- { role: docker, tags: [docker] } - { role: k3s, tags: [k3s] }
- { role: microservices, tags: [microservices, ms] } - { role: microservices, tags: [microservices, ms] }