|
| 1 | +--- |
| 2 | +name: helm-dev-environment |
| 3 | +description: Start up, tear down, and configure the local Kubernetes development environment for OpenShell. Uses k3d (Docker-backed k3s) + Skaffold + Helm. Covers cluster lifecycle, optional add-ons (Keycloak OIDC, Envoy Gateway), and port mappings. Trigger keywords - local k8s, local cluster, k3d, skaffold, helm dev, start cluster, stop cluster, tear down cluster, delete cluster, create cluster, helm:k3s, helm:skaffold, local dev environment, dev cluster, k8s dev, envoy gateway local, keycloak local. |
| 4 | +--- |
| 5 | + |
| 6 | +# Helm Dev Environment |
| 7 | + |
| 8 | +Set up, run, and tear down the local Kubernetes development environment for OpenShell. |
| 9 | +The stack is: **k3d** (Docker-backed k3s) for the cluster, **Skaffold** for image builds and Helm deploys, and the **OpenShell Helm chart** (`deploy/helm/openshell/`). |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- Docker Desktop (macOS) or Docker Engine (Linux) running |
| 16 | +- `mise install` completed (provides `k3d`, `kubectl`, `skaffold`, `helm`) |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Startup |
| 21 | + |
| 22 | +### 1. Create the cluster |
| 23 | + |
| 24 | +```bash |
| 25 | +mise run helm:k3s:create |
| 26 | +``` |
| 27 | + |
| 28 | +Creates a k3d cluster and merges its kubeconfig into the worktree-local `kubeconfig` file. |
| 29 | +Also applies base manifests (`deploy/kube/manifests/agent-sandbox.yaml`). Traefik is |
| 30 | +disabled at cluster creation time. |
| 31 | + |
| 32 | +**Multi-worktree support:** the cluster name is derived from the last component of the |
| 33 | +current git branch (e.g. branch `kube-support/local-dev/tmutch` → cluster |
| 34 | +`openshell-dev-tmutch`). Each worktree therefore gets its own isolated cluster and its |
| 35 | +own `kubeconfig` file. Override with `HELM_K3S_CLUSTER_NAME` to force a specific name |
| 36 | +or share one cluster across worktrees. |
| 37 | + |
| 38 | +Port mappings created at cluster time (cannot be changed without recreating): |
| 39 | + |
| 40 | +| Host port | Target | Used by | |
| 41 | +|-----------|--------|---------| |
| 42 | +| `8080` | Port `80` via k3d load balancer | Envoy Gateway LoadBalancer service (`values-gateway.yaml`) | |
| 43 | + |
| 44 | +Override with env vars before running `helm:k3s:create`: |
| 45 | +- `HELM_K3S_LB_HOST_PORT` (default: `8080`) |
| 46 | + |
| 47 | +### 2. Deploy OpenShell |
| 48 | + |
| 49 | +**Iterative dev** (rebuilds on file changes, recommended during active development): |
| 50 | +```bash |
| 51 | +mise run helm:skaffold:dev |
| 52 | +``` |
| 53 | + |
| 54 | +**One-shot deploy** (build once and leave running): |
| 55 | +```bash |
| 56 | +mise run helm:skaffold:run |
| 57 | +``` |
| 58 | + |
| 59 | +Both commands build the `gateway` and `supervisor` images and deploy the OpenShell Helm |
| 60 | +chart. The `pkiInitJob` hook runs on first install to generate mTLS secrets. Envoy Gateway is opt-in; see the Optional Add-ons section below. |
| 61 | + |
| 62 | +The gateway Service uses ClusterIP. Access is via Envoy Gateway (port `8080`) or `kubectl port-forward`. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Teardown |
| 67 | + |
| 68 | +### Remove the Helm releases (keep cluster) |
| 69 | + |
| 70 | +```bash |
| 71 | +mise run helm:skaffold:delete |
| 72 | +``` |
| 73 | + |
| 74 | +### Delete the cluster entirely |
| 75 | + |
| 76 | +```bash |
| 77 | +mise run helm:k3s:delete |
| 78 | +``` |
| 79 | + |
| 80 | +This removes the k3d cluster and all resources. Kubeconfig context is left behind |
| 81 | +but will point to a deleted cluster — safe to ignore or clean up manually. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Optional Add-ons |
| 86 | + |
| 87 | +Each add-on requires uncommenting the corresponding `valuesFiles` entry in |
| 88 | +`deploy/helm/openshell/skaffold.yaml` before running `helm:skaffold:dev` or `helm:skaffold:run`. |
| 89 | + |
| 90 | +### Envoy Gateway (Gateway API / GRPCRoute) |
| 91 | + |
| 92 | +Envoy Gateway is already installed by Skaffold (the `envoy-gateway` Helm release in |
| 93 | +`skaffold.yaml`). To activate routing: |
| 94 | + |
| 95 | +1. Uncomment `#- values-gateway.yaml` in `skaffold.yaml` |
| 96 | +2. Redeploy: `mise run helm:skaffold:run` |
| 97 | +3. Apply the GatewayClass: `mise run helm:gateway:apply` |
| 98 | +4. Access: `http://127.0.0.1:8080` |
| 99 | + |
| 100 | +`values-gateway.yaml` creates a `Gateway` (listener on port 80, class `eg`) and a |
| 101 | +`GRPCRoute` in the `openshell` namespace. Envoy Gateway provisions a LoadBalancer |
| 102 | +service for the proxy; klipper-lb binds it to hostPort 80, reachable via the |
| 103 | +`8080:80` load balancer port mapping. |
| 104 | + |
| 105 | +### Keycloak OIDC |
| 106 | + |
| 107 | +One-time setup — only needed once per cluster lifetime: |
| 108 | + |
| 109 | +```bash |
| 110 | +mise run keycloak:k8s:setup |
| 111 | +``` |
| 112 | + |
| 113 | +This deploys Keycloak (`quay.io/keycloak/keycloak:24.0`) into the `keycloak` namespace, |
| 114 | +imports the openshell realm from `scripts/keycloak-realm.json`, and prints a port-forward |
| 115 | +command for acquiring tokens from the CLI. |
| 116 | + |
| 117 | +Then activate OIDC in the OpenShell Helm chart: |
| 118 | +1. Uncomment `#- values-keycloak.yaml` in `skaffold.yaml` |
| 119 | +2. Redeploy: `mise run helm:skaffold:run` |
| 120 | + |
| 121 | +To remove Keycloak: |
| 122 | +```bash |
| 123 | +mise run keycloak:k8s:teardown |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Cluster Lifecycle (suspend/resume) |
| 129 | + |
| 130 | +Stop the cluster without losing state (faster than delete/recreate): |
| 131 | +```bash |
| 132 | +mise run helm:k3s:stop |
| 133 | +mise run helm:k3s:start |
| 134 | +``` |
| 135 | + |
| 136 | +Check cluster status: |
| 137 | +```bash |
| 138 | +mise run helm:k3s:status |
| 139 | +``` |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## Key Files |
| 144 | + |
| 145 | +| Path | Purpose | |
| 146 | +|------|---------| |
| 147 | +| `deploy/helm/openshell/skaffold.yaml` | Skaffold config — images, Helm releases, values overlays | |
| 148 | +| `deploy/helm/openshell/values.yaml` | Default Helm values | |
| 149 | +| `deploy/helm/openshell/values-skaffold.yaml` | Dev overrides (image pull policy, local image names) | |
| 150 | +| `deploy/helm/openshell/values-gateway.yaml` | Envoy Gateway GRPCRoute + Gateway overlay | |
| 151 | +| `deploy/helm/openshell/values-keycloak.yaml` | Keycloak OIDC overlay | |
| 152 | +| `deploy/kube/manifests/envoy-gateway-openshell.yaml` | GatewayClass for Envoy Gateway (`mise run helm:gateway:apply`) | |
| 153 | +| `tasks/scripts/helm-k3s-local.sh` | k3d cluster create/delete/start/stop/status | |
| 154 | +| `tasks/scripts/keycloak-k8s-setup.sh` | Keycloak deploy + realm import | |
0 commit comments