The k3s VM on the Mac Mini¶
Kind: how-to (install and operate)
Everything Linux on the Mac mini runs in one Lima VM k3s with one k3s node
(ADR 0022).
It replaces the two VMs ops and ci of ADR 0020 and ADR 0021. This page installs and operates the
VM itself; what runs in it has its own page.
Mac mini (macOS account agent-ops)
└── LaunchDaemon io.lima-vm.daemon.k3s cluster/mac-mini/host/
└── Lima VM k3s: vz, Rosetta, Ubuntu 24.04, cluster/mac-mini/lima/k3s.yaml
6 vCPUs, 9 GiB, 100 GiB, no mounts, no forwarded ports
└── k3s, one node; Flux applies ./cluster/mac-mini cluster/mac-mini/flux/
├── kube-system: generic-device-plugin (/dev/net/tun) components/generic-device-plugin/
├── keda: KEDA's operator, starts the ci pods components/keda/
├── ci: Gitea Actions runners, rootless, a pod per job Gitea Actions Runners on the Mac Mini
├── ops-agent: the operational agent Install the operational agent on the Mac mini
└── agents: agent runners, a pod per task not built yet
| Namespace | Pod security | Reaches |
|---|---|---|
ops-agent |
no ingress (NetworkPolicy); the only namespace with the hetzner-mgmt break-glass kubeconfig | hetzner-mgmt, Taskbase, Gitea, GitHub |
ci |
not privileged: a pod user namespace (hostUsers: false), rootless dind; ingress only from ci, egress only to DNS and the Internet |
Gitea, Harbor, registries, downloads |
kube-system |
k3s and the device plugin, privileged | — |
Why one account, agent-ops. Whoever owns the Lima instance can limactl shell k3s and be
root in the VM, which holds the break-glass kubeconfig. So the VM belongs to its own standard
account, not to agent-runner (whose agents run with full access) or to the admin's Homebrew. CI
no longer needs an account of its own: its jobs run unprivileged inside the VM
(ADR 0022 Q1),
so the ci-runner account of ADR 0021 is not created.
Install¶
The owner does this once, as the admin on the Mac mini rebuilt per
Mac Mini Rebuild, which has installed lima and flux, Rosetta, and
created the account agent-ops. No key or token goes into Git, a task or a comment.
limactl --version # 2.2 or later
git clone --depth 1 https://gitea.prod.skatzi.com/Skatzi/platform.git /tmp/platform
# 1. The VM, created (not started) as agent-ops, then started at boot by the LaunchDaemon
sudo install -o agent-ops -g staff -m 644 /tmp/platform/cluster/mac-mini/lima/k3s.yaml /Users/agent-ops/k3s.yaml
sudo -iu agent-ops /opt/homebrew/bin/limactl --tty=false create --name k3s /Users/agent-ops/k3s.yaml
sudo install -o root -g wheel -m 644 /tmp/platform/cluster/mac-mini/host/io.lima-vm.daemon.k3s.plist /Library/LaunchDaemons/
sudo launchctl enable system/io.lima-vm.daemon.k3s
sudo launchctl bootstrap system /Library/LaunchDaemons/io.lima-vm.daemon.k3s.plist
# The first start downloads Ubuntu and installs k3s (about 3 minutes). Then:
sudo -iu agent-ops /opt/homebrew/bin/limactl list k3s # STATUS Running
alias k='sudo -iu agent-ops /opt/homebrew/bin/limactl shell k3s sudo k3s kubectl'
k get nodes # one node, Ready
sudo -iu agent-ops /opt/homebrew/bin/limactl shell k3s sysctl kernel.apparmor_restrict_unprivileged_userns # = 0
# 2. Flux, with a read-only deploy key. helm-controller is for the ops-agent HelmRelease.
# flux ... --export and kubectl kustomize only print YAML and read no cluster; k applies it in the VM.
flux install --export --components=source-controller,kustomize-controller,helm-controller | k apply -f -
flux create secret git flux-system --namespace=flux-system \
--url=ssh://git@gitea.prod.skatzi.com/Skatzi/platform.git --export | k apply -f -
k -n flux-system get secret flux-system -o jsonpath='{.data.identity\.pub}' | base64 -d; echo
# Gitea → Skatzi/platform → Settings → Deploy Keys → Add: title "mac-mini-k3s flux",
# this public key, and leave "Enable write access" off.
# 3. Point Flux at cluster/mac-mini
kubectl kustomize /tmp/platform/cluster/mac-mini/flux | k apply -f -
k -n flux-system get gitrepository,kustomization # all Ready=True within a few minutes
k -n kube-system get pods -l app.kubernetes.io/name=generic-device-plugin # 1/1 Running
k get node -o jsonpath='{.items[0].status.allocatable.devic\.es/tun}'; echo # 64
rm -rf /tmp/platform
limactl autostart enable --condition=boot cannot be used: it must be run by the instance's owner
with sudo, and agent-ops is not an admin. The plist is what it would write. Never run limactl
stop k3s: it unloads that daemon.
Then install what runs in it, in this order: the runners (Gitea Actions Runners on the Mac Mini → Install, #1466), then the operational agent (Install the operational agent on the Mac mini, #1452). Until then their pods wait for the Secrets those steps create.
Done when the checks above pass, and after sudo shutdown -r now the node is Ready again
within about 5 minutes and sudo launchctl print system/io.lima-vm.daemon.k3s | grep state shows
running.
Operating¶
- Configuration changes go through Git: Flux applies
cluster/mac-minievery 10 minutes, and Renovate updates image and chart versions there, as on hetzner-mgmt. - k3s upgrades: when Renovate bumps
k3sVersioninlima/k3s.yaml, run k3s's installer in the VM with the new version. The template only installs k3s on first boot:
sudo -iu agent-ops /opt/homebrew/bin/limactl shell k3s sudo sh -c 'curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="<version>" INSTALL_K3S_EXEC="server --write-kubeconfig-mode 600 --secrets-encryption --disable=traefik --disable=servicelb --disable=metrics-server" sh -'
The ci pods depend on hostUsers: false and procMount, so check after an upgrade that the
runners are online again. If they are not, CI stops; it does not open up.
- Flux upgrades: Renovate does not track Flux in the VM; it is installed by whatever flux CLI
Homebrew has. To upgrade, run brew upgrade flux, then re-run install step 2's first command
with the new CLI.
- Other template changes (CPU, memory, image, the sysctl) need a new VM. A larger disk does
not: see Grow the disk.
1. sudo launchctl bootout system/io.lima-vm.daemon.k3s.
2. As agent-ops: limactl stop k3s, limactl delete k3s, then limactl create from the new
template.
3. Repeat install steps 1 to 3. The deploy key is new, so replace it in Gitea.
4. Recreate the Secrets of what runs in it: the runners' token (#1466's step) and the operator's
Secrets (#1452's step). The runners register again under new names; delete the old, offline
entries in Gitea.
- The Ubuntu image stays 24.04 until Rosetta runs on a newer kernel (ADR 0021).
- Size: 9 GiB is ADR 0020's and ADR 0021's VMs added up. Re-measure after the first week:
limactl shell k3s free -m, memory_pressure on the Mac, and OOM kills with
limactl shell k3s sudo dmesg | grep -i oom.
Image cleanup¶
The kubelet removes unused images from k3s's image store once the disk passes
image-gc-high-threshold, and stops at image-gc-low-threshold. Its defaults (85 % and 80 %) are
too late here: the two ci pods pull their job images into their own emptyDirs at the same
time, and that is where the disk ran out (ENOSPC, #2229). lima/k3s.yaml sets 60 % and
50 % with the drop-in /etc/rancher/k3s/config.yaml.d/50-image-gc.yaml, written by the
provision script at every VM start. Images that a running container uses are never removed; an
image removed between jobs is pulled again by the next pod that needs it.
To apply it to the running VM without waiting for its next start, run this on the Mac mini as the admin. Restarting k3s does not stop running containers.
L() { sudo -iu agent-ops /opt/homebrew/bin/limactl shell k3s sudo "$@"; } # a function: zsh doesn't word-split $L
L sh -c 'mkdir -p /etc/rancher/k3s/config.yaml.d && printf "kubelet-arg:\n - image-gc-high-threshold=60\n - image-gc-low-threshold=50\n" > /etc/rancher/k3s/config.yaml.d/50-image-gc.yaml'
L systemctl restart k3s
L sh -c 'sleep 20; k3s kubectl get nodes' # Ready
L df -h / # the kubelet trims to about 50 % within minutes
Cache volume¶
local-path does not enforce a PVC's size, so the ci namespace's actions/cache volume
act-cache grew past its 10Gi claim (11 GB on 2026-11-01, #2323). The trim container in the
act-cache pod removes entries past 8 GiB every 5 minutes, superseded copies first, then the
least recently restored
(CI runners on the Mac mini → Caches and memory).
After each pass, the container logs the size, so the operational agent can read it with its read
access to ci (kubectl --context mac-mini -n ci logs deploy/act-cache -c trim, #2415).
Measured on 2026-11-11 (#2397) over the pod's 3.5 days of CI (1,026 passes since 2026-11-07): the
cache never passed 8192M. From 2026-11-08 on it stayed between 7845M and 8192M, last at 8181M; it
was at 4610M when the pod started. Nearly all the eviction is the cache server's own
(deleted cache: … in the act-cache container's log, size_limit: 8GiB): trim removed two
entries in that time. Finished runner pods stayed within the ScaledJob's history limits (5
successful, 5 failed), so ttlSecondsAfterFinished is not needed. On the Mac mini as the admin:
L() { sudo -iu agent-ops /opt/homebrew/bin/limactl shell k3s sudo "$@"; }
L k3s kubectl -n ci logs deploy/act-cache -c trim --tail=20 # "Cache at 7800M of 8192M", "Removed cache entry ..."
L sh -c 'du -sh /var/lib/rancher/k3s/storage/*_ci_act-cache' # the same, from the VM: at most ~8.0G plus uploads in progress
Grow the disk¶
A larger disk: in lima/k3s.yaml does not need a new VM: Lima grows the disk of an existing
instance in place, so k3s's data and the Secrets stay. The disk went from 50 to 100 GiB in #2229,
after CI jobs failed with ENOSPC when the two ci pods ran heavy jobs at once. The disk is
sparse: the Mac holds only what the VM has written.
How Lima does it (v2.2.1 source, the version on the Mac mini; minimumLimaVersion is 2.2.0):
limactl edit k3s --disk 100setsdisk: "100GiB"in the instance's own~/.lima/k3s/lima.yaml. It refuses a running instance and refuses to shrink (cmd/limactl/edit.go,pkg/limayaml/validate.go). Lima's docs recommend it: Resizing the VM's primary disk.- The next
limactl startcompares the disk file with that size and grows it before booting (prepareDiskinpkg/instance/start.go): withqemu-img resize, or without QEMU by truncating the raw file, which keeps it sparse. - In the guest, Lima's cloud-init config sets
growpart: {mode: auto, devices: ['/']}(pkg/cidata/cidata.TEMPLATE.d/user-data), and cloud-init'sgrowpartandresizefsrun on every boot (frequency = PER_ALWAYSin cc_growpart.py and cc_resizefs.py). So/dev/vda1grows at that boot. If it does not, step 5 has the manual command.
What stops, and for how long. Plan about 15 minutes; the VM itself is down for about 5. Everything
in the VM stops: the operational agent, the Mac mini CI runners (mac-mini-…), and the agent
runners in agents once they run there. The hetzner-mgmt CI runners keep taking jobs, so CI only
gets slower. The mac-mini agent runner on macOS is not in the VM and keeps running. Pick a quiet
moment.
Run this on the Mac mini as the admin; the limactl commands run as agent-ops.
alias lima='sudo -iu agent-ops /opt/homebrew/bin/limactl'
alias k='sudo -iu agent-ops /opt/homebrew/bin/limactl shell k3s sudo k3s kubectl'
# 1. Pause. In the Taskbase control room, pause the runner `ops-agent` and wait until it runs
# nothing. Then let KEDA start no new CI pod, and wait until no ci pod is left
# (a job's page in Gitea names its runner; jobs still waiting go to hetzner-mgmt):
k -n flux-system patch kustomization ci --type merge -p '{"spec":{"suspend":true}}'
k -n ci annotate scaledjob gitea-act-runner autoscaling.keda.sh/paused=true
k -n ci get pods # repeat until "No resources found"
# Stop the host check, so it neither restarts k3s nor opens a dr issue meanwhile:
sudo launchctl bootout system/com.skatzi.ops-env-check
# 2. Stop the VM. Stop k3s and its containers first, so the guest shuts down within the
# 20 s launchd gives the LaunchDaemon. Never `limactl stop k3s` (see Install).
lima shell k3s sudo sh -c 'systemctl stop k3s && /usr/local/bin/k3s-killall.sh && sync'
sudo launchctl bootout system/io.lima-vm.daemon.k3s
lima list k3s # STATUS Stopped (repeat until it is)
# 3. Keep a copy for the rollback: an APFS clone, instant and taking no space until the disk changes.
sudo -iu agent-ops cp -c .lima/k3s/disk .lima/k3s-disk.before-resize
sudo -iu agent-ops cp .lima/k3s/lima.yaml .lima/k3s-lima.yaml.before-resize
# 4. Grow it and start it again with the LaunchDaemon.
lima --tty=false edit k3s --disk 100 # "Instance `k3s` configuration edited"
sudo launchctl bootstrap system /Library/LaunchDaemons/io.lima-vm.daemon.k3s.plist
sudo grep -h 'Resize instance' /Users/agent-ops/.lima/k3s/*.stderr.log # ... from 50GiB to 100GiB
lima list k3s # STATUS Running, DISK 100GiB (within ~3 min)
# 5. Check the guest grew its root filesystem.
lima shell k3s df -h / # /dev/vda1 about 98G
# Only if it still shows about 48G:
# lima shell k3s sudo sh -c 'growpart /dev/vda 1 && resize2fs /dev/vda1'
# 6. Resume.
k get nodes # one node, Ready (within ~5 min)
k -n ci annotate scaledjob gitea-act-runner autoscaling.keda.sh/paused-
k -n flux-system patch kustomization ci --type merge -p '{"spec":{"suspend":false}}'
sudo launchctl bootstrap system /Library/LaunchDaemons/com.skatzi.ops-env-check.plist
# In the Taskbase control room, resume the runner `ops-agent`.
Done when df -h / shows about 98G, the node is Ready, ops-agent is online in the Taskbase
control room, and a CI job (re-run a recent one) ran on a mac-mini-… runner and passed. Then
delete the copies: sudo -iu agent-ops rm .lima/k3s-disk.before-resize .lima/k3s-lima.yaml.before-resize.
Rollback, if the instance does not start (lima list k3s is not Running after 5 minutes):
read /Users/agent-ops/.lima/k3s/ha.stderr.log and launchd.stderr.log, then put back the copies
and start the 50 GiB VM as it was. Lima sees the disk at its configured size and resizes nothing.
sudo launchctl bootout system/io.lima-vm.daemon.k3s
sudo -iu agent-ops mv .lima/k3s-disk.before-resize .lima/k3s/disk
sudo -iu agent-ops mv .lima/k3s-lima.yaml.before-resize .lima/k3s/lima.yaml
sudo launchctl bootstrap system /Library/LaunchDaemons/io.lima-vm.daemon.k3s.plist
Then resume as in step 6 and record what the log showed in the task. If even the old disk does not start, the VM is recreated as Other template changes above describes.
Logs¶
- Lima:
/Users/agent-ops/.lima/k3s/ha.stderr.logandlaunchd.stderr.log(readable withsudo). - k3s:
limactl shell k3s sudo journalctl -u k3s.