Skip to content

Instantly share code, notes, and snippets.

@adamreese
Created March 13, 2024 15:01
Show Gist options
  • Save adamreese/1a06a47a6514eabe1945bab3e90897f1 to your computer and use it in GitHub Desktop.
Save adamreese/1a06a47a6514eabe1945bab3e90897f1 to your computer and use it in GitHub Desktop.
Lima VM with k3s
# This template requires Lima v0.14.0 or later and macOS 13.
images:
- location: "https://cloud-images.ubuntu.com/releases/23.10/release-20240125/ubuntu-23.10-server-cloudimg-amd64.img"
arch: "x86_64"
digest: "sha256:a7700ca87b691246cf57812c63f64a8ab0d6702c00f04c8f6efd97513bab5d59"
- location: "https://cloud-images.ubuntu.com/releases/23.10/release-20240125/ubuntu-23.10-server-cloudimg-arm64.img"
arch: "aarch64"
digest: "sha256:1072e90dd339fd7ba1e82b6c1c3b03183287ca4a6da52c04eaeb0e5653a59bc7"
- location: "https://cloud-images.ubuntu.com/releases/23.10/release/ubuntu-23.10-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/23.10/release/ubuntu-23.10-server-cloudimg-arm64.img"
arch: "aarch64"
vmType: "vz"
rosetta:
enabled: true
binfmt: true
mounts:
- location: "~"
- location: "/tmp/lima"
writable: true
mountType: "virtiofs"
networks:
# The "vzNAT" IP address is accessible from the host, but not from other guests.
- vzNAT: true
env:
TERM: xterm-256color
# 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/bash
set -eux -o pipefail
if [ ! -d /var/lib/rancher/k3s ]; then
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --write-kubeconfig-mode 644" sh -
fi
probes:
- script: |
#!/bin/bash
set -eux -o pipefail
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
copyToHost:
- guest: "/etc/rancher/k3s/k3s.yaml"
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
deleteOnStop: true
message: |
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
------
export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
kubectl ...
------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment