tool-containers
Menu
GitHub (opens in new tab)

Run devbox with Kubernetes

pod.yaml runs devbox as a single non-root pod that sleeps until you open a shell in it with kubectl exec.

Images
  • GHCRghcr.io/hambn/devbox
  • Docker Hubdocker.io/hambn/devbox
Use case
Disposable cluster development pod
Source
tools/base/devbox/docs/kubernetes (opens in new tab)
On this page

Prerequisites

  • A Kubernetes cluster and kubectl configured for it.

Open a shell

Shell
kubectl apply -f pod.yaml
kubectl wait --for=condition=Ready pod/devbox
kubectl exec -it devbox -- zsh -l

Copy files in and out with kubectl cp:

Shell
kubectl cp ./src devbox:/workspace/src
kubectl cp devbox:/workspace/out ./out

Workspace

/workspace is an emptyDir and is deleted with the pod. Replace it with a PersistentVolumeClaim to keep your work, or use the Helm recipe.

The pod runs as UID 1000 with every capability dropped and allowPrivilegeEscalation: false, so sudo and ping fail. No Docker daemon runs in the pod; set DOCKER_HOST to use a remote one.

Files

  • pod.yaml defines the pod, its security context, and resource limits.

Cleanup

Shell
kubectl delete -f pod.yaml

File contents

pod.yaml38 lines
# kubectl apply -f pod.yaml && kubectl exec -it devbox -- zsh -l
apiVersion: v1
kind: Pod
metadata:
  name: devbox
  labels:
    app.kubernetes.io/name: devbox
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    runAsGroup: 1000
    fsGroup: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
    - name: devbox
      image: ghcr.io/hambn/devbox:ubuntu-full
      imagePullPolicy: Always
      command: ["sleep", "infinity"]
      workingDir: /workspace
      securityContext:
        allowPrivilegeEscalation: false
        capabilities:
          drop: ["ALL"]
      resources:
        requests:
          cpu: 250m
          memory: 512Mi
        limits:
          cpu: "2"
          memory: 4Gi
      volumeMounts:
        - name: workspace
          mountPath: /workspace
  volumes:
    - name: workspace
      emptyDir: {}

Topics