Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/templates/k3s.yaml
2614 views
1
# Deploy kubernetes via k3s (which installs a bundled containerd).
2
# $ limactl start ./k3s.yaml
3
# $ limactl shell k3s kubectl
4
#
5
# It can be accessed from the host by exporting the kubeconfig file;
6
# the ports are already forwarded automatically by lima:
7
#
8
# $ export KUBECONFIG=$(limactl list k3s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
9
# $ kubectl get no
10
# NAME STATUS ROLES AGE VERSION
11
# lima-k3s Ready control-plane,master 69s v1.21.1+k3s1
12
13
# A multi-node cluster can be created by starting multiple instances of this template
14
# connected via the `lima:user-v2` network.
15
#
16
# $ limactl start --name k3s-0 --network lima:user-v2 template:k3s
17
# $ printf "https://lima-%s.internal:6443\n" k3s-0
18
# (The url for the start command printed here)
19
# $ limactl shell k3s-0 sudo cat /var/lib/rancher/k3s/server/node-token
20
# (The token for the start command printed here)
21
#
22
# $ limactl start --name k3s-1 --network lima:user-v2 template:k3s \
23
# --set '.param.url="<URL_FROM_ABOVE>" | .param.token="<TOKEN_FROM_ABOVE>"'
24
25
minimumLimaVersion: 2.0.0
26
27
base: template:_images/ubuntu-lts
28
29
# Mounts are disabled in this template, but can be enabled optionally.
30
mounts: []
31
# containerd is managed by k3s, not by Lima, so the values are set to false here.
32
containerd:
33
system: false
34
user: false
35
provision:
36
- mode: system
37
script: |
38
#!/bin/sh
39
if [ ! -d /var/lib/rancher/k3s ]; then
40
{{if not ( and .Param.url .Param.token )}}
41
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --write-kubeconfig-mode 644" sh -
42
{{else}}
43
curl -sfL https://get.k3s.io | K3S_URL={{.Param.url}} K3S_TOKEN={{.Param.token}} sh -
44
{{end}}
45
fi
46
probes:
47
- script: |
48
#!/bin/bash
49
set -eux -o pipefail
50
{{if not ( and .Param.url .Param.token )}}
51
if ! timeout 30s bash -c "until test -f /etc/rancher/k3s/k3s.yaml; do sleep 3; done"; then
52
echo >&2 "k3s is not running yet"
53
exit 1
54
fi
55
{{else}}
56
# create an empty file so that the "copyToHost" does not fail
57
sudo mkdir -p /etc/rancher/k3s && sudo touch /etc/rancher/k3s/k3s.yaml
58
{{end}}
59
hint: |
60
The k3s kubeconfig file has not yet been created.
61
Run "limactl shell k3s sudo journalctl -u k3s" to check the log.
62
If that is still empty, check the bottom of the log at "/var/log/cloud-init-output.log".
63
copyToHost:
64
- guest: "/etc/rancher/k3s/k3s.yaml"
65
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
66
deleteOnStop: true
67
message: |
68
{{- if not ( and .Param.url .Param.token ) -}}
69
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
70
------
71
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
72
kubectl ...
73
------
74
{{end}}
75
param:
76
url: ""
77
token: ""
78
79