diff --git a/deploy/create-secrets.sh b/deploy/create-secrets.sh index ffb1456..08db240 100755 --- a/deploy/create-secrets.sh +++ b/deploy/create-secrets.sh @@ -47,6 +47,10 @@ apply() { # name, then kubectl create arguments echo "applied Secret $name" } +if [ -z "$dry" ]; then + # The first run comes before the first apply, which is what would otherwise create the namespace. + kubectl create namespace "$ns" --dry-run=client -o yaml | kubectl apply -f - >/dev/null +fi for f in "$src"/*.env "$src"/*/; do [ -e "$f" ] || continue name=$(basename "$f" .env); name=${name%/} diff --git a/docs/deployment.md b/docs/deployment.md index 036de95..1ef5438 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -26,7 +26,7 @@ The Service names matter: - mobile-api and the portal find the gateway and mobile-api through `APIGATEWAYURL` and `MOBILE_API_BASE_URL`. **Health probes:** -- **Java services:** liveness `GET /actuator/health/liveness`, readiness `GET /actuator/health/readiness`. Spring Boot turns these on by itself on Kubernetes. `GET /actuator/health` also works everywhere. +- **Java services:** liveness `GET /actuator/health/liveness`, readiness `GET /actuator/health/readiness`. mobile-api does not switch these on by itself (measured: 404 without the setting), so the prod settings set `MANAGEMENT_HEALTH_PROBES_ENABLED=true` for every Java pod. Use the liveness path for the startup probe too: `GET /actuator/health` is 503 on service-email while no mail server is set. - **Admin portal:** it has no health endpoint. Use a TCP probe on port 3000, or `GET /login`, which returns 200 without a session. **The Java images run as root and listen on port 80** (the base image sets no user). A cluster that enforces `runAsNonRoot` or the restricted Pod Security level must allow them. @@ -50,7 +50,7 @@ Everything below runs from the repository root, on `main`, with `kubectl` pointe deploy/create-secrets.sh --dry-run # checks every key is filled in; prints names, never values deploy/create-secrets.sh # creates or updates the Secrets in the co-lite namespace ``` - Leave `co-lite-whatsapp.env` out until WhatsApp is connected (step 9). + The script creates the `co-lite` namespace if it is missing. Leave `co-lite-whatsapp.env` out until WhatsApp is connected (step 9). 5. **Pick the release.** Choose a commit on `main` whose CI run pushed the images, and pin it: ```sh deploy/set-release.sh <40-character commit sha> @@ -61,7 +61,13 @@ Everything below runs from the repository root, on `main`, with `kubectl` pointe kubectl apply -k deploy/k8s/overlays/prod kubectl -n co-lite rollout status deploy --timeout=10m ``` - All ten Deployments start together. A service that comes up before the ones it calls retries or is restarted by its probe, so no manual order is needed. Each Java pod gets up to 5 minutes to start. + All ten Deployments start together; each Java pod gets up to 5 minutes to start. Starting them together has not been tried on the cluster yet. If a pod keeps restarting, apply in the old order instead and wait for each step to be ready: + 1. `service-system`, `service-auth`, `service-counter`, `service-member`, `service-log`, `service-email`, `service-whatsapp`; + 2. `api-gateway`; + 3. `mobile-api`; + 4. `admin-portal`. + + Use `kubectl -n co-lite rollout restart deploy/` once the services it calls are ready. 7. Commit the overlay with the new SHA, so `main` records what runs. 8. Check the Custom HTML frame header (section 8). 9. Connect WhatsApp in Meta (section 11) whenever you are ready. Until then the inbox says "WhatsApp is not configured". To switch it on: fill in `whatsapp.env` in the overlay and `co-lite-whatsapp.env` in `secrets/`, then run `create-secrets.sh` and apply again. @@ -405,7 +411,7 @@ The templates are in `deploy/k8s/secrets.example/`, one file per Secret, with pl - A send that Meta accepts without a message id is stored as failed. A send that never gets an answer stays "Sending"; nothing sweeps it. - Media is streamed with `;charset=UTF-8` added to its content type; browsers ignore it. - Meta's media download address is not checked to be a Meta host before the access token is sent with it. -- **WhatsApp webhook and outages.** If `service-whatsapp` is down or answers with an error, the webhook answers 503 and Meta sends the event again, for up to 7 days; a message is never stored twice. The same happens right after `service-whatsapp` starts while `service-system` is unreachable. Keep `service-system` up before `service-whatsapp` (section 2). +- **WhatsApp webhook and outages.** If `service-whatsapp` is down or answers with an error, the webhook answers 503 and Meta sends the event again, for up to 7 days; a message is never stored twice. The same happens right after `service-whatsapp` starts while `service-system` is unreachable. So on the first apply, check that `service-system` is ready before Meta starts sending (section 2, step 6). - **Client addresses for rate limits.** mobile-api takes a caller's address for its rate limits from the first entry of `X-Forwarded-For` when the header is present (`HttpReqRespUtils` in core-libs). On the webhook route, a caller can set that header itself and so pick its own limit bucket. The webhook still rejects anything Meta did not sign, so this only weakens the flood limit (6000 calls per 10 minutes per address). Check that Traefik replaces an `X-Forwarded-For` sent by an untrusted caller instead of passing it on (`forwardedHeaders.insecure` off, `trustedIPs` limited to real proxies). - **Landing pages.** diff --git a/openspec/changes/add-k8s-deployment/tasks.md b/openspec/changes/add-k8s-deployment/tasks.md index 781983d..0ec96d9 100644 --- a/openspec/changes/add-k8s-deployment/tasks.md +++ b/openspec/changes/add-k8s-deployment/tasks.md @@ -50,6 +50,12 @@ - Verify: run it with `--dry-run` against a filled test folder; it prints only the Secret names and the key names. - Verify: a missing key is refused, and the refusal names the key. - Done: the dry run lists seven Secrets with their key names only. A missing `MYSQLPWD` is refused, and so is a placeholder `MYSQLPWD`. + - The real path ran in the check container, with `kubectl apply` stubbed: + - the `co-lite` namespace is created first, because the first run comes before any apply; + - seven Secrets carry the right keys and decode to the filled values; + - the registry Secret is a dockerconfigjson for `gitea.containerverse.dev`; + - no value appears on stdout. + - mobile-api's probes were proven on a throwaway container. Without `MANAGEMENT_HEALTH_PROBES_ENABLED` its liveness and readiness paths are missing; with it, all three return 200. ## 5. CI and docs