|
1 | | -# Local Kubernetes Setup (No Ingress, With Knative) |
| 1 | +# Local Kubernetes Setup |
2 | 2 |
|
3 | | -This document describes a local Kubernetes setup for the Constructive stack that: |
| 3 | +Two modes are available for local k8s development. Both use the `constructive-functions` namespace. |
4 | 4 |
|
5 | | -- Runs on a local cluster (kind, minikube, k3d, etc.). |
6 | | -- Uses a single Postgres Deployment (no CNPG operator). |
7 | | -- Uses a single MinIO Deployment (no MinIO Tenant/Operator). |
8 | | -- Keeps Knative + Kourier for jobs/functions. |
9 | | -- Uses a single namespace: `interweb`. |
10 | | -- Exposes everything via `kubectl port-forward` and localhost URLs. |
11 | | -- Runs email functions in dry-run mode, so Mailgun secrets are optional. |
| 5 | +## Option A: Plain k8s (local-simple) — Recommended |
12 | 6 |
|
13 | | -See the repository docs and manifests for the authoritative configuration. |
| 7 | +Uses plain Deployments + Services. No operators needed. This is the default for `make skaffold-dev` and CI. |
14 | 8 |
|
15 | | -## Prerequisite: GHCR image pull secret |
| 9 | +See [DEVELOPMENT.md](../DEVELOPMENT.md#k8s-local-development-skaffold) for full setup instructions. |
16 | 10 |
|
17 | | -The dashboard and database job images are hosted on GitHub Container Registry |
18 | | -(`ghcr.io`). Before applying the local overlay, you must create the `ghcr-pull` |
19 | | -image pull secret in the `interweb` namespace so the cluster can pull these |
20 | | -images. |
21 | | - |
22 | | -1. Create a `k8s/.env` file (this file is gitignored) with your GHCR |
23 | | - credentials: |
24 | | - |
25 | | - ```bash |
26 | | - # k8s/.env |
27 | | - GH_USERNAME=your-ghcr-username |
28 | | - GH_PAT_TOKEN=your-ghcr-read-packages-token |
29 | | - GH_EMAIL=you@example.com |
30 | | - ``` |
31 | | - |
32 | | -2. Ensure your `kubectl` context points at your local cluster (kind, minikube, |
33 | | - k3d, etc.). |
34 | | - |
35 | | -3. From the `k8s` directory, create or update the `ghcr-pull` secret: |
36 | | - |
37 | | - ```bash |
38 | | - cd k8s |
39 | | - make k8s-pull-secret |
40 | | - ``` |
| 11 | +```bash |
| 12 | +make skaffold-dev # builds, deploys, watches for changes |
| 13 | +``` |
41 | 14 |
|
42 | | -This will create a `ghcr-pull` `docker-registry` secret in the `interweb` |
43 | | -namespace, which is referenced by the `dashboard` Deployment and the |
44 | | -`constructive-db` Job. |
| 15 | +## Option B: Knative (local) |
45 | 16 |
|
46 | | -## Step 1: Create a local Kubernetes cluster |
| 17 | +Uses Knative Serving + Kourier for functions (closer to production). Requires operator install. |
47 | 18 |
|
48 | | -Setup with docker-desktop. Enable kubernetes on docker desktop |
| 19 | +### Step 1: Create a local cluster |
49 | 20 |
|
50 | | -## Step 2: Install Knative (operators-knative-only) |
| 21 | +Docker Desktop (enable Kubernetes), kind, k3d, or minikube. |
51 | 22 |
|
52 | | -The local setup keeps Knative + Kourier for jobs/functions but does **not** |
53 | | -require ingress or CNPG. From the `k8s` directory: |
| 23 | +### Step 2: Install Knative |
54 | 24 |
|
55 | 25 | ```bash |
56 | | -cd k8s |
| 26 | +cd k8s/scripts/setup |
57 | 27 | make operators-knative-only |
58 | 28 | ``` |
59 | 29 |
|
60 | | -This will: |
61 | | - |
62 | | -- Install Knative Serving + Kourier. |
63 | | -- Configure Knative to use an internal domain (`svc.cluster.local`) so Knative |
64 | | - services are reachable inside the cluster. |
65 | | - |
66 | | -For the “no ingress, single Postgres, single MinIO” local setup, the |
67 | | -`operators-knative-only` target is sufficient. |
| 30 | +This installs Knative Serving + Kourier and configures an internal domain (`svc.cluster.local`). |
68 | 31 |
|
69 | | -## Step 3: Apply the local overlay |
70 | | - |
71 | | -With your cluster and operators ready, apply the local Kustomize overlay: |
| 32 | +### Step 3: GHCR pull secret |
72 | 33 |
|
73 | 34 | ```bash |
74 | | -cd k8s |
75 | | - |
76 | | -# Apply the entire local stack (namespace, Postgres Deployment, MinIO, |
77 | | -# Constructive server/admin/dashboard, pgAdmin, jobs, and functions) |
78 | | -make kustomize-local |
| 35 | +kubectl create namespace constructive-functions --dry-run=client -o yaml | kubectl apply -f - |
| 36 | +kubectl create secret docker-registry ghcr-pull \ |
| 37 | + --docker-server=ghcr.io \ |
| 38 | + --docker-username=YOUR_USERNAME \ |
| 39 | + --docker-password=YOUR_GH_PAT_TOKEN \ |
| 40 | + --docker-email=your@email.com \ |
| 41 | + -n constructive-functions |
| 42 | +kubectl patch serviceaccount default -n constructive-functions \ |
| 43 | + -p '{"imagePullSecrets": [{"name": "ghcr-pull"}]}' |
79 | 44 | ``` |
80 | 45 |
|
81 | | -You can inspect the rendered YAML without applying it by running: |
| 46 | +### Step 4: Deploy |
82 | 47 |
|
83 | 48 | ```bash |
84 | | -make render-local |
| 49 | +make skaffold-dev-knative |
85 | 50 | ``` |
86 | 51 |
|
87 | | -## Step 4: Verify workloads |
88 | | - |
89 | | -Check that pods are starting in the `interweb` namespace: |
| 52 | +### Step 5: Verify |
90 | 53 |
|
91 | 54 | ```bash |
92 | | -kubectl get namespaces |
93 | | -kubectl get pods -n interweb |
94 | | -kubectl get svc -n interweb |
| 55 | +kubectl get pods -n constructive-functions |
| 56 | +kubectl get ksvc -n constructive-functions |
95 | 57 | ``` |
96 | 58 |
|
97 | | -You should see at least: |
98 | | - |
99 | | -- `deployment/constructive-server` |
100 | | -- `deployment/dashboard` |
101 | | -- `deployment/knative-job-service` |
102 | | -- `deployment/postgres` |
103 | | -- `ksvc/simple-email`, `ksvc/send-email-link` |
104 | | - |
105 | | -## Step 5: Access services via port-forward |
106 | | - |
107 | | -The local setup does not use an Ingress; access is via `kubectl port-forward`. |
108 | | -Convenience targets are provided in `k8s/Makefile`. From the `k8s` directory: |
109 | | - |
110 | | -```bash |
111 | | -cd k8s |
112 | | - |
113 | | -# Constructive Server (API + GraphQL) -> http://localhost:8080 |
114 | | -make proxy-server |
115 | | - |
116 | | -# Explorer (GraphQL explorer UI) -> http://localhost:8081 |
117 | | -make proxy-explorer |
118 | | - |
119 | | -# Dashboard UI -> http://localhost:3000 |
120 | | -make proxy-web |
121 | | -``` |
| 59 | +## Knative Resource Trimming (CI / constrained environments) |
122 | 60 |
|
123 | | -Run each of these in its own terminal (Ctrl+C to stop). You can also reach |
124 | | -pgAdmin if desired: |
| 61 | +Knative's control-plane components request significant resources by default. On small clusters (kind in CI, minikube with low memory), you may need to shrink them: |
125 | 62 |
|
126 | 63 | ```bash |
127 | | -kubectl -n interweb port-forward svc/pgadmin 3001:80 |
| 64 | +# Knative Serving control-plane |
| 65 | +kubectl -n knative-serving set resources deploy/activator \ |
| 66 | + --requests=cpu=50m,memory=80Mi --limits=cpu=200m,memory=256Mi |
| 67 | +kubectl -n knative-serving set resources deploy/autoscaler \ |
| 68 | + --requests=cpu=25m,memory=80Mi --limits=cpu=200m,memory=256Mi |
| 69 | +kubectl -n knative-serving set resources deploy/controller \ |
| 70 | + --requests=cpu=50m,memory=100Mi --limits=cpu=300m,memory=512Mi |
| 71 | +kubectl -n knative-serving set resources deploy/webhook \ |
| 72 | + --requests=cpu=25m,memory=80Mi --limits=cpu=200m,memory=256Mi |
| 73 | +kubectl -n knative-serving set resources deploy/net-kourier-controller \ |
| 74 | + --requests=cpu=25m,memory=80Mi --limits=cpu=200m,memory=256Mi |
| 75 | + |
| 76 | +# Kourier gateway |
| 77 | +kubectl -n kourier-system set resources deploy/3scale-kourier-gateway \ |
| 78 | + --requests=cpu=25m,memory=80Mi --limits=cpu=200m,memory=256Mi |
| 79 | + |
| 80 | +# CoreDNS (optional — scale to 1 replica) |
| 81 | +kubectl -n kube-system scale deploy/coredns --replicas=1 |
| 82 | +kubectl -n kube-system set resources deploy/coredns \ |
| 83 | + --requests=cpu=50m,memory=70Mi --limits=cpu=200m,memory=170Mi |
| 84 | + |
| 85 | +# Restart pods so changes take effect |
| 86 | +kubectl -n knative-serving rollout restart deploy/activator deploy/autoscaler \ |
| 87 | + deploy/controller deploy/webhook deploy/net-kourier-controller |
| 88 | +kubectl -n kourier-system rollout restart deploy/3scale-kourier-gateway |
| 89 | +kubectl -n kube-system rollout restart deploy/coredns |
128 | 90 | ``` |
129 | 91 |
|
130 | | -With these steps, you have a fully functional local Kubernetes environment for |
131 | | -the Constructive stack using the `overlays/local` manifests. |
| 92 | +This is not needed for the `local-simple` profile (no Knative). The CI workflow currently uses `local-simple` via Skaffold, so Knative trimming is not applied. If CI switches back to the Knative-based `local` overlay in the future, add these commands after operator install. |
0 commit comments