Files
zuul-jobs/roles/ensure-kubernetes/tasks/microk8s.yaml
Ian Wienand 99678c46e0 ensure-kubernetes: add microk8s support
Add microk8s support to the ensure-kubernetes role.  This installs via
a snap, and is currently only implemented for Ubuntu Jammy.

Mostly this is a straight-forward installation.  I did notice though
it needs a little more time to be stable in the test, so the timeout
is bumped slightly.

microk8s is the Ubuntu "blessed" way of doing things.  This should be
a better choice for Ubuntu platforms, because minikube is tightly tied
to cri-o, which is only packaged through kubic, which is currently in
some sort of deprecated but best-effort supported mode [1].  This was
inspired by an outage where the kubic gpg expired.  This appears fixed
now.

[1] https://kubic.opensuse.org/blog/2022-06-10-kubic-retired/

Change-Id: Id3e31c70a35dde218e35e7c50964f8a3c0348150
2023-01-08 08:05:40 -08:00

59 lines
1.2 KiB
YAML

- name: Check distro
assert:
that: ansible_distribution_release == 'jammy'
msg: 'This role only supported on Jammy'
- name: Install snapd
become: yes
package:
name: snapd
state: present
- name: Install microk8s snap
become: yes
command: 'snap install microk8s --classic --channel={{ ensure_kubernetes_microk8s_channel }}'
- name: Install add-ons
become: yes
command: '/snap/bin/microk8s enable {{ ensure_kubernetes_microk8s_addons | join(" ") }}'
- name: Install kubectl wrapper
become: yes
copy:
content: |
#!/bin/bash
/snap/bin/microk8s.kubectl "$@"
dest: /usr/local/bin/kubectl
owner: root
group: root
mode: 0755
- name: Allow zuul user kubectl access
become: yes
user:
name: 'zuul'
groups: 'microk8s'
append: yes
- name: Create .kube directory
file:
path: "{{ ansible_user_dir }}/.kube"
state: directory
mode: 0755
- name: Populate kube config
become: yes
shell: /snap/bin/microk8s config > {{ ansible_user_dir }}/.kube/config
- name: Ensure we can read config
become: yes
file:
path: "{{ ansible_user_dir }}/.kube/config"
owner: zuul
group: zuul
state: touch
mode: 0644
- name: Reset connection to pickup group
meta: reset_connection