Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
8.0 KiB
8.0 KiB
Design
Context
- Images: CI publishes ten images to
gitea.containerverse.dev/solvway/, each tagged with the commit SHA and withlatest. - What
docs/deployment.mdalready fixes:- the Service names and ports;
- the probes;
- every environment variable, and whether it is secret or plain;
- the two mounted files (
appkeys.jsonfor the gateway, the Pub/Subkey.jsonfor the other Java images); - the setup order;
- the Traefik routes (portal on
co-lite.containerverse.dev, plus the webhook path).
- Outside the cluster manifests:
- MySQL, prepared by the DBA;
- Redis ("use the existing Redis");
- Google Pub/Sub.
- Tools: the repository has no Kubernetes files, and this machine has Docker but no kubectl.
Goals / Non-Goals
Goals:
- One
kubectl apply -k deploy/k8s/overlays/proddeploys the whole system once the Secrets exist. - A check that fails on the mistakes that would hurt in production:
- a public route to an internal service;
- an image on
latest; - secret data in git;
- two service-counter replicas.
Non-Goals:
- Helm charts, GitOps tooling (Argo CD or Flux), or automatic deploys from CI. A person applies each release.
- Running MySQL, Redis or a Pub/Sub emulator in the cluster.
- A local Kubernetes preview. The owner previews the system with the docker-compose stack.
- Autoscaling, resource tuning beyond sensible requests, and NetworkPolicies. These can follow once the cluster's policy is known.
Decisions
1. Kustomize, with a base and a prod overlay
- Choice: plain YAML under
deploy/k8s/base/, plusdeploy/k8s/overlays/prod/for the image SHA, the plain settings, the namespace and the routes. - Why:
- Kustomize is built into kubectl, so the deployer installs nothing.
- The YAML reads like the handover doc.
- Rejected:
- Helm: templating for one environment adds code, and Helm would need installing.
- Raw YAML without overlays: the SHA would then be edited in ten files.
2. The image SHA is set in one place
- How: the overlay's
images:list setsnewTagfor all ten images. A smalldeploy/set-release.sh <sha>rewrites those ten lines. - Rollback: run
set-release.sh <previous sha>and apply again. Every release is a commit onmain, so the SHA in git history is the record of what ran.
3. Secrets are created by a script from git-ignored files, not stored as manifests
- Templates:
deploy/k8s/secrets.example/holds one.envtemplate per Secret (fromdocs/deployment.mdsection 9), plus anappkeys.jsontemplate. - Filling them in: the deployer copies the folder to
deploy/k8s/secrets/, which git ignores, and fills it in. - Creating them:
deploy/create-secrets.shrunskubectl create secret generic --from-env-file / --from-file ... --dry-run=client -o yaml | kubectl apply -f -. It never prints a value. - Rejected:
- Sealed Secrets or SOPS: new tooling and keys to manage, for a two-developer team. They can come later.
- A Kustomize
secretGenerator: it would put the values into the rendered output, which the check must stay able to forbid.
4. Traefik IngressRoute for the public routes
- What: the
prodoverlay holds two IngressRoutes onco-lite.containerverse.dev:/toadmin-portal:3000;Path(/api/public/whatsapp/webhook)tomobile-api:80.
- Why: the handover doc already states the routes as Traefik rules, and the cluster runs Traefik.
- TLS: a
tls:block whose cert resolver (or cert-manager secret) name is a single field in the overlay (see Open Questions). - Rejected: a standard Ingress with Traefik annotations. Exact-path matching is less clear there, and nothing else in the cluster needs portability.
5. The check runs from one pinned container
- What:
deploy/check.shsends thedeploy/folder through stdin intoalpine/k8s:1.33.4, pinned by digest. That one image has kubectl and kustomize, kubeconform, and python3 with PyYAML. - Why stdin: it also works against CI's remote Docker daemon, where bind mounts would not reach the files.
- Steps:
- Kustomize renders the overlay.
- kubeconform validates the result. The Traefik schemas come from the CRDs catalog.
check_rules.pyapplies the rules.
- Modes:
--self-testruns every rule against its fixture indeploy/check-fixtures/.--releasealso refuses any<…>placeholder. CI runs the plain check, because the cluster facts are still placeholders in git; the deployer runs--releasebefore applying.
- Rejected: separate kubectl, kubeconform and Python images. That is three pulls and three pins for the same result.
6. Pod settings
- Common to all pods:
- one replica each;
TZleft to the image;GCP_CREDENTIAL_FILEand thekey.jsonmount on every Java pod exceptapi-gatewayandservice-whatsapp;imagePullSecretsset to one named pull secret.
- service-counter:
strategy: Recreate, so a rollout never runs two copies at once and the daily summary is never sent twice. - Probes: the startup probe uses
/actuator/health/livenessand allows up to 5 minutes. The overall/actuator/healthis 503 on service-email while no mail server is configured.- mobile-api does not turn its probe groups on by itself, so the settings set
MANAGEMENT_HEALTH_PROBES_ENABLED=truefor every Java pod. - Both facts were measured on the local containers.
- mobile-api does not turn its probe groups on by itself, so the settings set
- WhatsApp Secret: referenced with
optional: true, so mobile-api and service-whatsapp start while WhatsApp is off. - Image tags: quoted in the overlay. A SHA made only of digits, or shaped like
1e45…, would otherwise be read as a number. - Requests: modest (
100mCPU and512Mifor the Java pods;256Mifor the portal), with no CPU limit.JAVA_OPTS=-Xmx384mkeeps the heap inside the memory limit. - Security context: the Java images run as root (documented). The manifests do not set
runAsNonRoot. If the cluster enforces it, that is a finding for the image, not a manifest workaround.
Risks / Trade-offs
- [A wrong cluster fact breaks the first apply] (CRD version, pull-secret name, TLS method). Mitigation: those facts are single overlay fields, listed under Open Questions, and the first apply is done together with the owner.
- [Secrets created by hand drift from the templates] Mitigation:
create-secrets.shrefuses to run if any key in a template is missing from the filled file. - [No automatic deploy means releases lag
main] This is accepted for go-live. Every release is a deliberate act with a recorded SHA. - [The check uses an image pulled from Docker Hub] Mitigation: it is pinned by version and digest.
- [kubeconform fetches the Traefik schema from GitHub] Without network access the check fails rather than skipping. CI already needs the network to pull images.
Migration Plan
- The DBA prepares MySQL, and the Pub/Sub topics and key are created (handover sections 3 and 5).
- Fill in
deploy/k8s/secrets/and rundeploy/create-secrets.sh. Create the registry pull secret. - Run
deploy/set-release.sh <sha>anddeploy/check.sh, thenkubectl apply -k deploy/k8s/overlays/prod. - Wait for every Deployment to roll out (
kubectl rollout status), then sign in as the first admin. - Rollback: run
set-release.sh <previous sha>, apply again, and wait for the rollout. Database changes are forward-only. A release that ran new SQL rolls back only to a SHA that works with that schema; the SQL files say which ones are safe.
Open Questions
These are single overlay fields. They are needed before the first real apply, not to build or check the manifests.
- Namespace: the default is
co-lite. - TLS: the Traefik cert resolver name (for example
letsencrypt), or a cert-manager ClusterIssuer. - Pull secret: its name for
gitea.containerverse.dev, if the cluster already has one. - Redis: the address of "the existing Redis".
- Public-pages hostname: the separate one for
/r,/i,/cand/p(handover section 8), if it should exist at go-live. - Access: who has kubectl access to the cluster for the first apply.