canonical / microk8s

MicroK8s is a small, fast, single-package Kubernetes for datacenters and the edge.
https://microk8s.io
Apache License 2.0
8.4k stars 767 forks source link

MicroK8s installation is failing when using launch configurations (1.27.2) #4041

Closed f-bn closed 3 months ago

f-bn commented 1 year ago

Summary

Hello :)

I would like to setup a small MicroK8s cluster using the new "launch configurations" feature available since version 1.27. However, this doesn't work well when I want to automate the deployment using a config file delivered by Ansible before installing the snap.

Some informations about my setup :

Here is my config file :

root@mk8s01:~# cat /etc/microk8s.yaml
---
version: 0.1.0
persistentClusterToken: my-token # I use a 32 characters length token
extraKubeAPIServerArgs:
  --authorization-mode: RBAC,Node
extraKubeletArgs:
  --cluster-dns: 10.152.183.10
  --cluster-domain: cluster.local
addons:
- name: dns
- name: rbac
- name: metrics-server

Here is the error message I got :

root@mk8s01:~# snap install microk8s --classic --channel=1.27/stable
error: cannot perform the following tasks:
- Run install hook of "microk8s" snap if present (run hook "install":
-----
+ source /snap/microk8s/5372/actions/common/utils.sh
++ [[ /snap/microk8s/5372/meta/hooks/install == \/\s\n\a\p\/\m\i\c\r\o\k\8\s\/\5\3\7\2\/\a\c\t\i\o\n\s\/\c\o\m\m\o\n\/\u\t\i\l\s\.\s\h ]]
+ '[' -f /var/snap/microk8s/5372/var/lock/installed.lock ']'
++ /snap/microk8s/5372/bin/uname -m
+ ARCH=x86_64
+ export LD_LIBRARY_PATH=/snap/microk8s/5372/lib:/snap/microk8s/5372/usr/lib:/snap/microk8s/5372/lib/x86_64-linux-gnu:/snap/microk8s/5372/usr/lib/x86_64-linux-gnu
+ LD_LIBRARY_PATH=/snap/microk8s/5372/lib:/snap/microk8s/5372/usr/lib:/snap/microk8s/5372/lib/x86_64-linux-gnu:/snap/microk8s/5372/usr/lib/x86_64-linux-gnu
+ export PATH=/snap/microk8s/5372/usr/sbin:/snap/microk8s/5372/usr/bin:/snap/microk8s/5372/sbin:/snap/microk8s/5372/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin:/usr/local/bin
+ PATH=/snap/microk8s/5372/usr/sbin:/snap/microk8s/5372/usr/bin:/snap/microk8s/5372/sbin:/snap/microk8s/5372/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin:/usr/local/bin
+ export OPENSSL_CONF=/snap/microk8s/5372/etc/ssl/openssl.cnf
+ OPENSSL_CONF=/snap/microk8s/5372/etc/ssl/openssl.cnf
+ is_strict
+ cat /snap/microk8s/5372/meta/snap.yaml
+ grep -q strict
+ grep confinement
+ return 1
+ cat /proc/1/environ
+ grep container=lxc
+ cp -r --preserve=mode /snap/microk8s/5372/default-args /var/snap/microk8s/5372/args
+ mv /var/snap/microk8s/5372/args/certs.d/localhost__32000 /var/snap/microk8s/5372/args/certs.d/localhost:32000
+ '[' -e /var/lib/kubelet ']'
+ ln -s /var/snap/microk8s/common/var/lib/kubelet /var/lib/kubelet
+ echo '`/var/lib/kubelet` linked to /var/snap/microk8s/common'
`/var/lib/kubelet` linked to /var/snap/microk8s/common
+ mkdir /var/snap/microk8s/5372/certs
+ cp /snap/microk8s/5372/certs/csr.conf.template /var/snap/microk8s/5372/certs/csr.conf.template
+ mkdir -p /var/snap/microk8s/common/etc/launcher
+ for config_file in "/etc/microk8s.yaml" "$SNAP_USER_COMMON/.microk8s.yaml" "$SNAP_COMMON/.microk8s.yaml" "$SNAP/microk8s.default.yaml"
+ '[' -f /etc/microk8s.yaml ']'
+ echo 'Found config file /etc/microk8s.yaml, will use to initialize cluster.'
Found config file /etc/microk8s.yaml, will use to initialize cluster.
+ cp /etc/microk8s.yaml /var/snap/microk8s/common/etc/launcher/install.yaml
+ /snap/microk8s/5372/bin/cluster-agent init --pre-init --config-file /var/snap/microk8s/common/etc/launcher/install.yaml
Error: failed to apply configuration: failed to apply config part 0: failed to configure persistent token: failed to open /var/snap/microk8s/5372/credentials/persistent-cluster-tokens.txt: open /var/snap/microk8s/5372/credentials/persistent-cluster-tokens.txt: no such file or directory
Usage:
   init [flags]

Flags:
  -c, --config-file string   configuration file to read, or '-' to read from stdin
  -h, --help                 help for init
  -p, --pre-init             apply pre-init configuration, do not restart services or manage addons
-----)

It's working fine without the persistentClusterToken directive, so I guess this is related with a missing "copy" in /var/snap/microk8s/5372/credentials/persistent-cluster-tokens.txt file during the bootstrap.

Reproduction Steps

  1. Create config file in /etc/microk8s.yaml or /root/snap/microk8s/common/.microk8s.yaml
  2. snap install microk8s --classic --channel=1.27/stable

Introspection Report

Can't provide it since the installation is failing

Thanks :)

ktsakalozos commented 1 year ago

Hi @f-bn

Thank you for reporting this. The issue is with the persistentClusterToken line. We try to append the provided token but the token's file is not created yet.

As a temporary workaround while we patch and release the fix for the problem you can set the persistentClusterToken after the installation of the snap:

With:

$ sudo cat /etc/microk8s.yaml
---
version: 0.1.0
extraKubeAPIServerArgs:
  --authorization-mode: RBAC,Node
extraKubeletArgs:
  --cluster-dns: 10.152.183.10
  --cluster-domain: cluster.local
addons:
- name: dns
- name: rbac
- name: metrics-server

And:

$ cat ./microk8s-token.yaml 
---
version: 0.1.0
persistentClusterToken: 12345678901234567890123456789012

Do:

sudo snap install microk8s --classic
sudo microk8s status --wait-ready
sudo snap set microk8s config="$(cat microk8s-token.yaml)"

Apologies for the inconvenience.

f-bn commented 1 year ago

Hi @ktsakalozos

No problem, thanks for the quick workaround :)

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.