---title: Kubernetes
weight: 4
---Single-node
{{< tabpane text=true >}} {{% tab header="kubeadm" %}}
limactl start template://k8s
export KUBECONFIG=$(limactl list k8s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
kubectl create deployment nginx --image nginx:alpine
kubectl create service nodeport nginx --node-port=31080 --tcp=80:80
Modify templates/k8s.yaml to change the kubeadm configuration.
See also https://kubernetes.io/docs/reference/setup-tools/kubeadm/. {{% /tab %}} {{% tab header="k3s" %}}
limactl start template://k3s
export KUBECONFIG=$(limactl list k3s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
kubectl create deployment nginx --image nginx:alpine
kubectl create service nodeport nginx --node-port=31080 --tcp=80:80
See also https://docs.k3s.io. {{% /tab %}} {{% tab header="k0s" %}}
limactl start template://k0s
export KUBECONFIG=$(limactl list k0s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
kubectl create deployment nginx --image nginx:alpine
kubectl create service nodeport nginx --node-port=31080 --tcp=80:80
See also https://docs.k0sproject.io/. {{% /tab %}} {{% tab header="RKE2" %}}
limactl start template://experimental/rke2
export KUBECONFIG=$(limactl list rke2 --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
kubectl create deployment nginx --image nginx:alpine
kubectl create service nodeport nginx --node-port=31080 --tcp=80:80
See also https://docs.rke2.io/. {{% /tab %}} {{% tab header="Usernetes" %}}
limactl start template://experimental/u7s
export KUBECONFIG=$(limactl list u7s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
kubectl create deployment nginx --image nginx:alpine
kubectl port-forward deployments/nginx 8080:80
See also https://github.com/rootless-containers/usernetes. {{% /tab %}} {{< /tabpane >}}
Multi-node
A multi-node cluster can be created by creating multiple VMs connected via the lima:user-v2 network.
The following templates are designed to support multi-node mode:
k8s (since Lima v2.0)
k3s (since Lima v2.1)
{{< tabpane text=true >}} {{% tab header="Lima v2.0" %}}
limactl start --name k8s-0 --network lima:user-v2 template:k8s
limactl shell k8s-0 sudo kubeadm token create --print-join-command
limactl start --name k8s-1 --network lima:user-v2 template:k8s
limactl shell k8s-1 sudo bash -euxc "kubeadm reset --force ; ip link delete cni0 ; ip link delete flannel.1 ; rm -rf /var/lib/cni /etc/cni"
limactl shell k8s-1 sudo <JOIN_COMMAND_FROM_ABOVE>
{{% /tab %}} {{% tab header="Lima v2.1 (k8s)" %}}
limactl start --name k8s-0 --network lima:user-v2 template:k8s
limactl shell k8s-0 sudo kubeadm token create --print-join-command
limactl start --name k8s-1 --network lima:user-v2 template:k8s \
--set '.param.url="https://<ADDRESS_FROM_ABOVE>" | .param.token="<TOKEN_FROM_ABOVE>" | \
.param.discoveryTokenCaCertHash="<DISCOVERY_TOKEN_CA_CERT_HASH_FROM_ABOVE>"'
{{% /tab %}} {{% tab header="Lima v2.1 (k3s)" %}}
limactl start --name k3s-0 --network lima:user-v2 template:k3s
printf "https://lima-%s.internal:6443\n" k3s-0
limactl shell k3s-0 sudo cat /var/lib/rancher/k3s/server/node-token
limactl start --name k3s-1 --network lima:user-v2 template:k3s \
--set '.param.url="<URL_FROM_ABOVE>" | .param.token="<TOKEN_FROM_ABOVE>"'
{{% /tab %}} {{< /tabpane >}}