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