diff --git a/templates/README.md b/templates/README.md index 04fed74e07f..80f5f0f32f9 100644 --- a/templates/README.md +++ b/templates/README.md @@ -55,6 +55,7 @@ Container image builders: Container orchestration: - [`faasd`](./faasd.yaml): [Faasd](https://docs.openfaas.com/deployment/edge/) +- [`k0s`](./k0s.yaml): [k0s](https://k0sproject.io/) Zero Friction Kubernetes - [`k3s`](./k3s.yaml): Kubernetes via k3s - [`k8s`](./k8s.yaml): Kubernetes via kubeadm - [`experimental/u7s`](./experimental/u7s.yaml): [Usernetes](https://github.com/rootless-containers/usernetes): Rootless Kubernetes diff --git a/templates/k0s.yaml b/templates/k0s.yaml new file mode 100644 index 00000000000..00fa61811e5 --- /dev/null +++ b/templates/k0s.yaml @@ -0,0 +1,69 @@ +# Deploy kubernetes via k0s (which installs a bundled containerd). +# $ limactl start ./k0s.yaml +# $ limactl shell k0s kubectl +# +# It can be accessed from the host by exporting the kubeconfig file; +# the ports are already forwarded automatically by lima: +# +# $ export KUBECONFIG=$(limactl list k0s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml') +# $ kubectl get no +# NAME STATUS ROLES AGE VERSION +# lima-k0s Ready control-plane 2m48s v1.33.2+k0s + +minimumLimaVersion: 1.1.0 + +base: template://_images/ubuntu-lts + +# Mounts are disabled in this template, but can be enabled optionally. +mounts: [] + +# containerd is managed by k0s, not by Lima, so the values are set to false here. +containerd: + system: false + user: false + +provision: +- mode: system + script: | + #!/bin/bash + set -eux -o pipefail + command -v k0s >/dev/null 2>&1 && exit 0 + + # install k0s prerequisites + curl -sfL https://get.k0s.sh | sh + +- mode: system + script: | + #!/bin/bash + set -eux -o pipefail + + # start k0s as a single node cluster + if ! systemctl status k0scontroller >/dev/null 2>&1; then + k0s install controller --single + fi + + systemctl start k0scontroller + +probes: +- description: "k0s to be running" + script: | + #!/bin/bash + set -eux -o pipefail + if ! timeout 30s bash -c "until sudo test -f /var/lib/k0s/pki/admin.conf; do sleep 3; done"; then + echo >&2 "k0s kubeconfig file has not yet been created" + exit 1 + fi + hint: | + The k0s control plane is not ready yet. + Run "limactl shell k0s sudo journalctl -u k0scontroller" to debug. + +copyToHost: +- guest: "/var/lib/k0s/pki/admin.conf" + host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml" + deleteOnStop: true +message: | + To run `kubectl` on the host (assumes kubectl is installed), run the following commands: + ------ + export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml" + kubectl ... + ------