| | # Devbox setup — live Git worktree environments on k3s |
| | Set up a system allowing multiple Git branches of an application to run simultaneously on a developer machine, with isolated environments, live re and individual HTTPS URLs. |
| | Work through the following steps in order. Verify the Cloudflare tunnel before enabling Cloudflare Access. |
| | ## Assumptions |
| | - Ubuntu (or similar) machine with sudo access. |
| | - Around 8 CPU cores and 32 GB RAM for 2–3 simultaneous environments, depending on the application. |
| | - The application repository is cloned locally. |
| | - The user has or will create a Cloudflare account and domain. |
| | ## Prerequisite — Application Helm chart |
| | The application needs Kubernetes manifests packaged as a Helm chart in deploy/worktree/. If they do not exist, inspect the application's architecture, Dockerfiles, Docker Compose configuration and development commands, and generate them first. |
| | The chart must: |
| | - Mount source code directly from the Git worktree using hostPath. |
| | - Run development servers with hot-reload and automatic dependency installation. |
| | - Deploy independent application services, databases and PVCs per environment. |
| | - Initialize databases from development dumps or seed scripts. |
| | - Expose services through an Ingress using ingressClassName: cloudflare-tunnel. |
| | - Configure frontend allowed hosts and HMR for dynamic HTTPS hostnames. |
| | - Allow optional services to be disabled through Helm values. |
| | ## Generate the environment manager |
| | If missing, generate an executable Bash script at deploy/worktree/env.sh supporting: |
| | bash | | | env.sh up [--path <worktree>] [--branch <branch>] [--slug <slug>] [--set k=v ...] | | | env.sh down [slug] | | | env.sh reset-db [slug] | | | env.sh status [slug] | | | env.sh list | | | |
| | - up: reuse or create a Git worktree and deploy it using helm upgrade --install. |
| | - down: uninstall the Helm release and delete its namespace, keeping the worktree. |
| | - reset-db: stop database pods, delete database PVCs and redeploy using existing Helm values. |
| | - status: display pods and environment URL. |
| | - list: display all environments, pod readiness and URLs. |
| | Implementation requirements: |
| | - Default to the current Git worktree when no path or branch is specified. |
| | - Generate a DNS-compatible slug from the branch name, limited to 45 characters. |
| | - Use wt-<slug> as the namespace, <slug> as the Helm release name and https://<slug>.<domain> as the URL. |
| | - Configure the domain, worktree directory and kubeconfig through WT_BASE_DOMAIN, WT_WORKTREES_DIR and WT_KUBECONFIG. |
| | - Always target the local k3s cluster (/etc/rancher/k3s/k3s.yaml by default), never the user's default Kubernetes context. |
| | - Pass branchName, worktreePath, baseDomain and additional --set arguments to Helm. |
| | - Resolve the Helm chart directory relative to the script's location. |
| | ## Setup steps |
| | ### 1. Tailscale (optional) |
| | For remote SSH access to the machine. Unrelated to the environment system itself. |
| | Guide the user through https://tailscale.com signup, then: |
| | bash | | | curl -fsSL https://tailscale.com/install.sh \| sh | | | sudo tailscale up | | | |
| | ### 2. k3s |
| | Install k3s with a kubeconfig readable by the developer: |
| | bash | | | curl -sfL https://get.k3s.io \| sh -s - --write-kubeconfig-mode 644 | | | |
| | ### 3. Helm |
| | k3s bundles kubectl but not Helm: |
| | bash | | | curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 \| bash | | | |
| | ### 4. Cloudflare account and domain |
| | Guide the user through creating a Cloudflare account. |
| | The base domain must be a zone in that account. Either purchase a domain through Cloudflare Registrar or add an existing domain and point its nameservers at Cloudflare. |
| | ### 5. Cloudflare API token |
| | Create an API token in My Profile → API Tokens with the following permissions: |
| | - Account → Cloudflare Tunnel → Edit |
| | - Zone → Zone → Read |
| | - Zone → DNS → Edit |
| | Scope the zone permissions to the development domain. Retrieve the Cloudflare Account ID. |
| | ### 6. Tunnel ingress controller |
| | Do not install cloudflared on the host or manually create tunnels and DNS records. |
| | Use the in-cluster cloudflare-tunnel-ingress-controller, which automatically creates the tunnel and DNS records for each environment. |
| | bash | | | export KUBECONFIG=/etc/rancher/k3s/k3s.yaml | | | kubectl create namespace cloudflare-tunnel-ingress-controller | | | kubectl -n cloudflare-tunnel-ingress-controller create secret generic cloudflare-api \ | | | --from-literal=api-token="<API_TOKEN>" \ | | | --from-literal=cloudflare-account-id="<ACCOUNT_ID>" \ | | | --from-literal=cloudflare-tunnel-name=devbox-worktrees | | | helm repo add strrl.dev https://helm.strrl.dev | | | helm repo update | | | helm upgrade --install cloudflare-tunnel-ingress-controller \ | | | strrl.dev/cloudflare-tunnel-ingress-controller \ | | | -n cloudflare-tunnel-ingress-controller \ | | | --set ingressClass.name=cloudflare-tunnel \ | | | --set cloudflare.secretRef.name=cloudflare-api \ | | | --set cloudflare.secretRef.apiTokenKey=api-token \ | | | --set cloudflare.secretRef.accountIDKey=cloudflare-account-id \ | | | --set cloudflare.secretRef.tunnelNameKey=cloudflare-tunnel-name | | | |
| | ### 7. inotify limits |
| | Multiple environments run several file watchers. Increase kernel limits to prevent hot-reload from silently failing. |
| | bash | | | sudo tee /etc/sysctl.d/99-worktree-envs.conf <<'EOF' | | | fs.inotify.max_user_instances=2048 | | | fs.inotify.max_user_watches=1048576 | | | EOF | | | sudo sysctl --system | | | |
| | ### 8. Environment configuration |
| | Configure the base domain and worktree directory persistently: |
| | bash | | | echo 'export WT_BASE_DOMAIN=example.com' >> ~/.bashrc | | | echo 'export WT_WORKTREES_DIR=$HOME/repo/my-app-worktrees' >> ~/.bashrc | | | source ~/.bashrc | | | |
| | Replace the domain and directory with the user's actual configuration. |
| | ### 9. First environment and tunnel verification |
| | Deploy an environment from main before enabling Cloudflare Access: |
| | bash | | | cd ~/repo/my-app | | | deploy/worktree/env.sh up --branch main | | | kubectl get pods -n wt-main -w | | | |
| | Once the pods are ready, verify DNS, tunnel, ingress, frontend, backend and database connectivity. |
| | bash | | | curl -s "https://main.${WT_BASE_DOMAIN}/" | | | |
| | Adapt the health-check endpoints to the application. |
| | After Cloudflare Access is enabled, perform automated HTTP checks locally against Kubernetes Services rather than unauthenticated public URLs. |
| | ### 10. Cloudflare Access |
| | In Cloudflare Zero Trust, create a self-hosted Access application for *.example.com. |
| | Configure an access policy allowing only authorized email addresses, using the One-time PIN login method. |
| | Every environment URL is now protected behind email authentication. |
| | ### 11. External services (if applicable) |
| | If the application uses external services, adapt their development configuration to support dynamic environment hostnames: |
| | - Object storage CORS allowed origins. |
| | - OAuth callback URLs. |
| | - Authentication and cookie configuration. |
| | - Webhook endpoints. |
| | Use development credentials and resources, not production ones. |
| | ### 12. Issue tracker MCP (optional) |
| | Connect the agent to the project's issue tracker. |
| | For example, with Linear: |
| | bash | | | claude mcp add --transport http linear https://mcp.linear.app/mcp | | | |
| | Authenticate via /mcp inside Claude Code. |
| | ### 13. End-to-end test |
| | Ask the agent to implement a feature or work on an issue. |
| | Verify that it creates a dedicated Git branch and worktree, deploys the environment, modifies the source code and returns a working HTTPS URL. |
| | Confirm that source code changes appear automatically without rebuilding images or redeploying the environment. |
| | ## Agent workflow |
| | Whenever asked to work on a feature or issue: |
| | 1. Retrieve the issue from the issue tracker, if applicable. |
| | 2. Create a dedicated Git branch and worktree. |
| | 3. Deploy the environment using env.sh up. |
| | 4. Implement changes directly in the worktree. |
| | 5. Run tests and verify application health locally. |
| | 6. Return the environment's public URL for review. |
| | Keep environments running until explicitly asked to remove them. Never delete Git worktrees when removing Kubernetes environments. |
| | ## Known limitations |
| | - OAuth providers may not support dynamically generated callback URLs. |
| | - External services may require additional CORS configuration. |
| | - Database resets delete environment-specific data and reinitialize it from development seeds or dumps. |
| | - The number of simultaneous environments depends on available CPU, RAM and storage. |
remote agentic devbox setup cocadmin
A developer published a step-by-step guide for running multiple Git branches of an application simultaneously on a single k3s machine, with each branch getting its own isolated namespace, database, PVCs and HTTPS URL. The setup pairs a Helm chart that mounts source code from Git worktrees via hostPath with a Bash environment manager (env.sh) that creates and tears down environments using helm upgrade --install, and routes traffic through a Cloudflare tunnel Ingress. The guide recommends roughly 8 CPU cores and 32 GB RAM for two to three concurrent environments.
Wrap helm upgrade --install in a script that maps each Git branch to its own wt-<slug> namespace and Cloudflare-tunnel URL, and always target the local k3s kubeconfig rather than the user's default context.
more in playbook: Running AI in productionRun your AI side-project on zahid.host
EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.