Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/templates/experimental/u7s.yaml
2621 views
1
# Deploy kubernetes via usernetes.
2
# $ limactl start ./u7s.yaml
3
# $ limactl shell u7s 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 u7s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
9
# $ kubectl get no
10
# NAME STATUS ROLES AGE VERSION
11
# u7s-lima-u7s Ready control-plane 33s v1.28.0
12
13
minimumLimaVersion: 2.0.0
14
15
base: template:_images/ubuntu-lts
16
17
# Mounts are disabled in this template, but can be enabled optionally.
18
mounts: []
19
# containerd is managed by Docker, not by Lima, so the values are set to false here.
20
containerd:
21
system: false
22
user: false
23
provision:
24
- mode: system
25
script: |
26
#!/bin/bash
27
set -eux -o pipefail
28
command -v kubectl >/dev/null 2>&1 && exit 0
29
version=$(curl -L -s https://dl.k8s.io/release/stable.txt)
30
case $(uname -m) in
31
x86_64) arch=amd64;;
32
aarch64) arch=arm64;;
33
esac
34
curl -L "https://dl.k8s.io/release/$version/bin/linux/$arch/kubectl" -o /usr/local/bin/kubectl
35
chmod 755 /usr/local/bin/kubectl
36
kubectl version --client
37
- mode: user
38
script: |
39
#!/bin/bash
40
set -eux -o pipefail
41
test -d ~/usernetes && exit 0
42
cd ~
43
git clone --branch=gen2-v20251218.0 https://github.com/rootless-containers/usernetes
44
- mode: user
45
script: |
46
#!/bin/bash
47
set -eux -o pipefail
48
cd ~/usernetes/init-host
49
sudo ./init-host.root.sh
50
./init-host.rootless.sh
51
- mode: user
52
script: |
53
#!/bin/bash
54
set -eux -o pipefail
55
test -e ~/usernetes/kubeconfig && exit 0
56
cd ~/usernetes
57
export KUBECONFIG="$(pwd)/kubeconfig"
58
make up
59
sleep 5
60
make kubeadm-init
61
# Installing a Pod network add-on
62
make install-flannel
63
# Control plane node isolation
64
make kubeconfig
65
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
66
# Symlink the kubeconfig file to the default location for kubectl
67
mkdir -p ~/.kube && ln -sf $KUBECONFIG ~/.kube/config
68
# Replace the server address with localhost, so that it works from the host.
69
# The original kubeconfig is kept unmodified, so that `kubeadm token create --print-join-command`
70
# can still print the reachable address.
71
sed -e "/server:/ s|https://.*:\([0-9]*\)$|https://127.0.0.1:\1|" $KUBECONFIG >kubeconfig.localhost
72
probes:
73
- description: "kubectl to be installed"
74
script: |
75
#!/bin/bash
76
set -eux -o pipefail
77
if ! timeout 30s bash -c "until command -v kubectl >/dev/null 2>&1; do sleep 3; done"; then
78
echo >&2 "kubectl is not installed yet"
79
exit 1
80
fi
81
hint: |
82
See "/var/log/cloud-init-output.log" in the guest
83
- description: "kubeadm to be completed"
84
script: |
85
#!/bin/bash
86
set -eux -o pipefail
87
if ! timeout 300s bash -c "until test -f ~/usernetes/kubeconfig; do sleep 3; done"; then
88
echo >&2 "k8s is not running yet"
89
exit 1
90
fi
91
hint: |
92
The k8s kubeconfig file has not yet been created.
93
- description: "kubernetes cluster to be running"
94
script: |
95
#!/bin/bash
96
set -eux -o pipefail
97
if ! timeout 300s bash -c "until kubectl version >/dev/null 2>&1; do sleep 3; done"; then
98
echo >&2 "kubernetes cluster is not up and running yet"
99
exit 1
100
fi
101
- description: "coredns deployment to be running"
102
script: |
103
#!/bin/bash
104
set -eux -o pipefail
105
kubectl wait -n kube-system --timeout=180s --for=condition=available deploy coredns
106
copyToHost:
107
- guest: "{{.Home}}/usernetes/kubeconfig.localhost"
108
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
109
deleteOnStop: true
110
message: |
111
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
112
------
113
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
114
kubectl ...
115
------
116
117