From 8876f70be87da4476953f5fea118750940c7a0ca Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 10 Feb 2026 15:58:58 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A4=96=20docs:=20add=20CloudNativePG?= =?UTF-8?q?=20example=20for=20CoderControlPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a multi-resource CloudNativePG example under `examples/cloudnativepg`, including namespace, CNPG `Cluster`, and `CoderControlPlane` manifests, plus a walkthrough README for deployment and access. --- _Generated with [`mux`](https://github.com/coder/mux) • Model: `openai:gpt-5.3-codex` • Thinking: `xhigh`_ --- _Generated with `mux` • Model: `openai:gpt-5.3-codex` • Thinking: `xhigh` • Cost: `$1.12`_ --- README.md | 4 + examples/cloudnativepg/README.md | 81 +++++++++++++++++++ examples/cloudnativepg/cnpg-cluster.yaml | 13 +++ examples/cloudnativepg/codercontrolplane.yaml | 18 +++++ examples/cloudnativepg/namespace.yaml | 6 ++ 5 files changed, 122 insertions(+) create mode 100644 examples/cloudnativepg/README.md create mode 100644 examples/cloudnativepg/cnpg-cluster.yaml create mode 100644 examples/cloudnativepg/codercontrolplane.yaml create mode 100644 examples/cloudnativepg/namespace.yaml diff --git a/README.md b/README.md index eee4c237..f6dcb5f3 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ kubectl apply -f config/samples/coder_v1alpha1_codercontrolplane.yaml kubectl get codercontrolplanes -A ``` +## Examples + +- [`examples/cloudnativepg/`](examples/cloudnativepg/) - Deploy a `CoderControlPlane` with a CloudNativePG-managed PostgreSQL backend. + ## KIND development cluster (for k9s demos) Bootstrap a KIND cluster and install CRDs/RBAC (**this also switches your current kubectl context**): diff --git a/examples/cloudnativepg/README.md b/examples/cloudnativepg/README.md new file mode 100644 index 00000000..315cddb0 --- /dev/null +++ b/examples/cloudnativepg/README.md @@ -0,0 +1,81 @@ +# CloudNativePG-backed CoderControlPlane example + +This example deploys a `CoderControlPlane` backed by a PostgreSQL cluster managed by [CloudNativePG](https://cloudnative-pg.io/). + +It creates: + +- a `coder` namespace +- a CloudNativePG `Cluster` named `coder-db` +- a `CoderControlPlane` named `coder` wired to the CloudNativePG app Secret (`coder-db-app`) + +## Prerequisites + +- A Kubernetes cluster +- `kubectl` configured for that cluster +- `helm` + +## 1. Install the CloudNativePG operator + +```bash +helm repo add cnpg https://cloudnative-pg.github.io/charts +helm repo update +helm upgrade --install cnpg cnpg/cloudnative-pg \ + --namespace cnpg-system \ + --create-namespace +``` + +## 2. Install the coder-k8s controller + +Follow [Deploy the controller (in-cluster)](../../docs/how-to/deploy-controller.md), or run: + +```bash +kubectl create namespace coder-system +kubectl apply -f config/crd/bases/ +kubectl apply -f deploy/rbac.yaml +kubectl apply -f deploy/controller-deployment.yaml +kubectl rollout status deployment/coder-k8s-controller -n coder-system +``` + +## 3. Deploy this example + +```bash +kubectl apply -f examples/cloudnativepg/ +``` + +Wait for PostgreSQL and verify the generated Secret: + +```bash +kubectl -n coder wait --for=condition=Ready cluster/coder-db --timeout=10m +kubectl -n coder get secret coder-db-app +``` + +Wait for the `CoderControlPlane` deployment: + +```bash +kubectl -n coder rollout status deployment/coder --timeout=10m +kubectl -n coder get codercontrolplane coder +``` + +## 4. Access Coder + +In one terminal: + +```bash +kubectl -n coder port-forward svc/coder 8080:80 +``` + +Then open: + +- + +Use the setup flow to create the first admin user. + +## Important limitation of this quickstart + +This example sets: + +- `CODER_ACCESS_URL=http://localhost:8080` + +That value is convenient for UI smoke tests through `kubectl port-forward`, but it is not suitable for end-to-end workspace connectivity because in-cluster components cannot reach your local `localhost`. + +For a full setup, expose Coder with an ingress/load balancer and set `CODER_ACCESS_URL` to a real external URL (for example, `https://coder.example.com`). diff --git a/examples/cloudnativepg/cnpg-cluster.yaml b/examples/cloudnativepg/cnpg-cluster.yaml new file mode 100644 index 00000000..6cc119d0 --- /dev/null +++ b/examples/cloudnativepg/cnpg-cluster.yaml @@ -0,0 +1,13 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: coder-db + namespace: coder +spec: + instances: 1 + storage: + size: 5Gi + bootstrap: + initdb: + database: coder + owner: coder diff --git a/examples/cloudnativepg/codercontrolplane.yaml b/examples/cloudnativepg/codercontrolplane.yaml new file mode 100644 index 00000000..2258d090 --- /dev/null +++ b/examples/cloudnativepg/codercontrolplane.yaml @@ -0,0 +1,18 @@ +apiVersion: coder.com/v1alpha1 +kind: CoderControlPlane +metadata: + name: coder + namespace: coder +spec: + replicas: 1 + service: + type: ClusterIP + port: 80 + extraEnv: + - name: CODER_PG_CONNECTION_URL + valueFrom: + secretKeyRef: + name: coder-db-app + key: uri + - name: CODER_ACCESS_URL + value: http://localhost:8080 diff --git a/examples/cloudnativepg/namespace.yaml b/examples/cloudnativepg/namespace.yaml new file mode 100644 index 00000000..67aec19c --- /dev/null +++ b/examples/cloudnativepg/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: coder + labels: + app.kubernetes.io/part-of: coder-k8s-example From e9acf275b14b8b077d9e65d42c3b7c815655bdde Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 10 Feb 2026 16:04:43 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=96=20fix:=20ensure=20namespace=20?= =?UTF-8?q?applies=20before=20namespaced=20example=20manifests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefix the namespace manifest filename and document the ordering so `kubectl apply -f examples/cloudnativepg/` succeeds on fresh clusters. --- _Generated with [`mux`](https://github.com/coder/mux) • Model: `openai:gpt-5.3-codex` • Thinking: `xhigh`_ --- _Generated with `mux` • Model: `openai:gpt-5.3-codex` • Thinking: `xhigh` • Cost: `$1.12`_ --- examples/cloudnativepg/{namespace.yaml => 00-namespace.yaml} | 0 examples/cloudnativepg/README.md | 2 ++ 2 files changed, 2 insertions(+) rename examples/cloudnativepg/{namespace.yaml => 00-namespace.yaml} (100%) diff --git a/examples/cloudnativepg/namespace.yaml b/examples/cloudnativepg/00-namespace.yaml similarity index 100% rename from examples/cloudnativepg/namespace.yaml rename to examples/cloudnativepg/00-namespace.yaml diff --git a/examples/cloudnativepg/README.md b/examples/cloudnativepg/README.md index 315cddb0..0bc17690 100644 --- a/examples/cloudnativepg/README.md +++ b/examples/cloudnativepg/README.md @@ -42,6 +42,8 @@ kubectl rollout status deployment/coder-k8s-controller -n coder-system kubectl apply -f examples/cloudnativepg/ ``` +The namespace manifest is prefixed (`00-namespace.yaml`) so `kubectl apply -f` creates `coder` before namespaced resources. + Wait for PostgreSQL and verify the generated Secret: ```bash