Skip to content

Instantly share code, notes, and snippets.

@bpmct
Created April 3, 2026 18:48
Show Gist options
  • Select an option

  • Save bpmct/91a0e96c78785b46757dc8ca99e20673 to your computer and use it in GitHub Desktop.

Select an option

Save bpmct/91a0e96c78785b46757dc8ca99e20673 to your computer and use it in GitHub Desktop.
Skill: Lightweight K8s (k3s) in Coder Workspaces

Lightweight K8s in Coder Workspaces

Spin up a minimal Kubernetes cluster inside a Coder workspace. Uses k3s with sudo (no systemd).

Limitations

  • Containers won't actually run. The OCI runtime fails with unsafe procfs because the workspace itself is a container. Pods stay in ContainerCreating. Fine for Terraform state bugs, k8s API-level issues, and anything that doesn't need running workloads.
  • Ephemeral — k3s state is lost on workspace restart.

Setup

# 1. Install k3s binary
curl -sfL https://get.k3s.io | \
  INSTALL_K3S_EXEC="--disable=traefik --write-kubeconfig-mode=644" sh - 2>&1 | tail -3
# Ignore the systemd error — expected in containers.

# 2. Start k3s manually (no systemd)
sudo nohup k3s server \
  --disable=traefik \
  --write-kubeconfig-mode=644 \
  > /tmp/k3s.log 2>&1 &

# 3. Wait for ready (~5-10s)
for i in $(seq 1 30); do
  sudo k3s kubectl get nodes 2>/dev/null | grep -q Ready && break
  sleep 2
done

# 4. Set up kubeconfig for non-root use
mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config
export KUBECONFIG=~/.kube/config

# 5. Verify
kubectl get nodes

Installing Terraform

TF_VERSION=1.13.0
cd /tmp
wget -q "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip"
unzip -o "terraform_${TF_VERSION}_linux_amd64.zip" -d "/tmp/tf${TF_VERSION//./}"
"/tmp/tf${TF_VERSION//./}/terraform" version

After workspace restart

k3s and its state are gone. Re-run the setup steps. Terraform state files on the workspace filesystem persist.

Terraform version reference (Coder releases)

Coder version Bundled Terraform
v2.28.7 1.13.0
main (HEAD) 1.14.5
pre-identity ≤ 1.11.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment