Skip to content

Commit 6ade5ae

Browse files
committed
Add usernetes with docker example
Will run Kubernetes in rootless docker, a.k.a. "usernetes". Add certificate for localhost so we can use it from the host. Signed-off-by: Anders F Björklund <[email protected]>
1 parent ee24d70 commit 6ade5ae

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Container orchestration:
4545
- [`faasd`](./faasd.yaml): [Faasd](https://docs.openfaas.com/deployment/faasd/)
4646
- [`k3s`](./k3s.yaml): Kubernetes via k3s
4747
- [`k8s`](./k8s.yaml): Kubernetes via kubeadm
48+
- [`experimental/u7s`](./experimental/u7s.yaml): [Usernetes](https://github.com/rootless-containers/usernetes): Rootless Kubernetes
4849

4950
Optional feature enablers:
5051
- [`vmnet`](./vmnet.yaml): ⭐enable [`vmnet.framework`](../docs/network.md)

examples/experimental/u7s.yaml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
# This template requires Lima v0.8.0 or later
14+
images:
15+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
16+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20231010/ubuntu-22.04-server-cloudimg-amd64.img"
17+
arch: "x86_64"
18+
digest: "sha256:5bed3f233c2422187e86089deea51bb8469dc2a26e96814ca41ff8f14dc80308"
19+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20231010/ubuntu-22.04-server-cloudimg-arm64.img"
20+
arch: "aarch64"
21+
digest: "sha256:5167c1b13cb33274955e36332ecb7b14f02b71fd19a37a9c1a3a0f8a805ab8e5"
22+
# Fallback to the latest release image.
23+
# Hint: run `limactl prune` to invalidate the cache
24+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
25+
arch: "x86_64"
26+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
27+
arch: "aarch64"
28+
29+
# Mounts are disabled in this template, but can be enabled optionally.
30+
mounts: []
31+
# containerd is managed by Docker, 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/bash
39+
set -eux -o pipefail
40+
command -v kubectl >/dev/null 2>&1 && exit 0
41+
version=$(curl -L -s https://dl.k8s.io/release/stable.txt)
42+
case $(uname -m) in
43+
x86_64) arch=amd64;;
44+
aarch64) arch=arm64;;
45+
esac
46+
curl -L "https://dl.k8s.io/release/$version/bin/linux/$arch/kubectl" -o /usr/local/bin/kubectl
47+
chmod 755 /usr/local/bin/kubectl
48+
kubectl version --client
49+
- mode: user
50+
script: |
51+
#!/bin/bash
52+
set -eux -o pipefail
53+
test -d ~/usernetes && exit 0
54+
cd ~
55+
git clone --branch=gen2-v20230919.0 https://github.com/rootless-containers/usernetes
56+
- mode: user
57+
script: |
58+
#!/bin/bash
59+
set -eux -o pipefail
60+
cd ~/usernetes/init-host
61+
sudo ./init-host.root.sh
62+
./init-host.rootless.sh
63+
- mode: user
64+
script: |
65+
#!/bin/bash
66+
set -eux -o pipefail
67+
test -e ~/usernetes/kubeconfig && exit 0
68+
cd ~/usernetes
69+
export KUBECONFIG=./kubeconfig
70+
patch --forward -r - kubeadm-config.yaml <<EOF
71+
@@ -7,6 +7,9 @@
72+
---
73+
apiVersion: kubeadm.k8s.io/v1beta3
74+
kind: ClusterConfiguration
75+
+apiServer:
76+
+ certSANs:
77+
+ - "127.0.0.1"
78+
networking:
79+
serviceSubnet: "10.96.0.0/16"
80+
podSubnet: "10.244.0.0/16"
81+
EOF
82+
make up
83+
sleep 5
84+
make kubeadm-init
85+
# Installing a Pod network add-on
86+
make install-flannel
87+
# Control plane node isolation
88+
make kubeconfig
89+
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
90+
# Replace the server address with localhost, so that it works also from the host
91+
sed -e "/server:/ s|https://.*:\([0-9]*\)$|https://127.0.0.1:\1|" -i $KUBECONFIG
92+
mkdir -p ~/.kube && cp -f $KUBECONFIG ~/.kube/config
93+
probes:
94+
- description: "kubectl to be installed"
95+
script: |
96+
#!/bin/bash
97+
set -eux -o pipefail
98+
if ! timeout 30s bash -c "until command -v kubectl >/dev/null 2>&1; do sleep 3; done"; then
99+
echo >&2 "kubectl is not installed yet"
100+
exit 1
101+
fi
102+
hint: |
103+
See "/var/log/cloud-init-output.log". in the guest
104+
- description: "kubeadm to be completed"
105+
script: |
106+
#!/bin/bash
107+
set -eux -o pipefail
108+
if ! timeout 300s bash -c "until test -f ~/usernetes/kubeconfig; do sleep 3; done"; then
109+
echo >&2 "k8s is not running yet"
110+
exit 1
111+
fi
112+
hint: |
113+
The k8s kubeconfig file has not yet been created.
114+
- description: "kubernetes cluster to be running"
115+
script: |
116+
#!/bin/bash
117+
set -eux -o pipefail
118+
if ! timeout 300s bash -c "until kubectl version >/dev/null 2>&1; do sleep 3; done"; then
119+
echo >&2 "kubernetes cluster is not up and running yet"
120+
exit 1
121+
fi
122+
- description: "coredns deployment to be running"
123+
script: |
124+
#!/bin/bash
125+
set -eux -o pipefail
126+
kubectl wait -n kube-system --timeout=180s --for=condition=available deploy coredns
127+
copyToHost:
128+
- guest: "{{.Home}}/usernetes/kubeconfig"
129+
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
130+
deleteOnStop: true
131+
message: |
132+
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
133+
------
134+
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
135+
kubectl ...
136+
------

0 commit comments

Comments
 (0)