mirror of
https://github.com/lima-vm/lima.git
synced 2026-10-28 11:44:35 +08:00
Now supports a parameter "mirror" for pulling the images from: mirror: "http://host.lima.internal:8080" A pull-through cache for docker.io and other registries is at: https://aceeric.github.io/ociregistry/ Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
95 lines
3.3 KiB
YAML
95 lines
3.3 KiB
YAML
# Deploy kubernetes via k3s (which installs a bundled containerd).
|
|
# $ limactl start ./k3s.yaml
|
|
# $ limactl shell k3s 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 k3s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
|
|
# $ kubectl get no
|
|
# NAME STATUS ROLES AGE VERSION
|
|
# lima-k3s Ready control-plane,master 69s v1.21.1+k3s1
|
|
|
|
# A multi-node cluster can be created by starting multiple instances of this template
|
|
# connected via the `lima:user-v2` network.
|
|
#
|
|
# $ limactl start --name k3s --network lima:user-v2 template:k3s
|
|
# $ printf "https://lima-%s.internal:6443\n" k3s
|
|
# (The url for the start command printed here)
|
|
# $ limactl shell k3s sudo cat /var/lib/rancher/k3s/server/node-token
|
|
# (The token for the start command printed here)
|
|
#
|
|
# $ limactl start --name k3s-1 --network lima:user-v2 template:k3s \
|
|
# --param url="<URL_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>"
|
|
|
|
minimumLimaVersion: 2.0.0
|
|
|
|
base: template:_images/ubuntu-lts
|
|
|
|
# Mounts are disabled in this template, but can be enabled optionally.
|
|
mounts: []
|
|
# containerd is managed by k3s, not by Lima, so the values are set to false here.
|
|
containerd:
|
|
system: false
|
|
user: false
|
|
provision:
|
|
- mode: system
|
|
script: |
|
|
#!/bin/sh
|
|
if [ ! -d /var/lib/rancher/k3s ]; then
|
|
{{- if .Param.proxy }}
|
|
INSTALL_K3S_ARTIFACT_URL={{.Param.proxy}}/HTTPS///github.com/k3s-io/k3s/releases/download
|
|
export INSTALL_K3S_ARTIFACT_URL
|
|
{{- end}}
|
|
{{if .Param.mirror }}
|
|
mkdir -p /etc/rancher/k3s
|
|
cat <<EOF >/etc/rancher/k3s/registries.yaml
|
|
mirrors:
|
|
"*":
|
|
endpoint:
|
|
- "{{.Param.mirror}}"
|
|
EOF
|
|
{{end}}
|
|
{{if not ( and .Param.url .Param.token )}}
|
|
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --write-kubeconfig-mode 644" sh -
|
|
{{else}}
|
|
curl -sfL https://get.k3s.io | K3S_URL={{.Param.url}} K3S_TOKEN={{.Param.token}} sh -
|
|
{{end}}
|
|
fi
|
|
probes:
|
|
- script: |
|
|
#!/bin/bash
|
|
set -eux -o pipefail
|
|
{{if not ( and .Param.url .Param.token )}}
|
|
if ! timeout 30s bash -c "until test -f /etc/rancher/k3s/k3s.yaml; do sleep 3; done"; then
|
|
echo >&2 "k3s is not running yet"
|
|
exit 1
|
|
fi
|
|
{{end}}
|
|
hint: |
|
|
The k3s kubeconfig file has not yet been created.
|
|
Run "limactl shell k3s sudo journalctl -u k3s" to check the log.
|
|
If that is still empty, check the bottom of the log at "/var/log/cloud-init-output.log".
|
|
copyToHost:
|
|
- guest: "/etc/rancher/k3s/k3s.yaml"
|
|
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
|
|
skipIfMissing: true
|
|
deleteOnStop: true
|
|
message: |
|
|
{{- if not ( and .Param.url .Param.token ) -}}
|
|
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
|
|
------
|
|
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
|
|
kubectl ...
|
|
------
|
|
{{end}}
|
|
param:
|
|
# The proxy to use when downloading artifacts from k3s.io
|
|
# For a local proxy use for instance "http://host.lima.internal:3142"
|
|
proxy: ""
|
|
# The mirror to use when pulling images from registry
|
|
# For a local mirror use for instance "http://host.lima.internal:8080"
|
|
mirror: ""
|
|
url: ""
|
|
token: ""
|