Deployment

Kubernetes

grit deploy --k8s writes the manifests for your project into deploy/k8s: the API, the frontends it actually has, a migration Job, a horizontal autoscaler, a config map, a secret template and a kustomization that ties them together. It deploys nothing. The files are yours to read, change and commit.

grit deploy --k8s --k8s-image registry.example.com/contacts-api:v1.4.2

Applying them

Three steps, and the order matters.

# 1. The secret, once. It is NOT in kustomization.yaml.
cp deploy/k8s/secret.example.yaml deploy/k8s/secret.yaml
$EDITOR deploy/k8s/secret.yaml
kubectl apply -f deploy/k8s/secret.yaml
# 2. The migration, every release, and wait for it.
kubectl apply -f deploy/k8s/migrate-job.yaml
kubectl wait --for=condition=complete --timeout=5m \
job/contacts-migrate-v1-4-2 -n contacts
# 3. Everything else.
kubectl apply -k deploy/k8s

Plain manifests, not a chart

These are plain Kubernetes objects with a kustomization, so kubectl apply -k works with nothing else installed. That is partly taste and mostly testability: every file is valid YAML, so Grit can check its own output by parsing it. A Helm chart cannot be checked that way, because {{- if .Values.x }} is not YAML, and a template that produces broken manifests looks exactly like one that does not until somebody runs it against a cluster.

If your team standardises on Helm, wrap these or use them as the body of a chart. Nothing here depends on how they are applied.

Why the probes are not /api/health

A Grit API serves three health endpoints, and they answer different questions. /api/health probes every dependency it has, which is what the System Health page needs. /healthz and /readyz exist for an orchestrator: liveness probes nothing on purpose, and readiness gates on the database alone.

The manifests use the second pair. Pointing readiness at /api/health means a slow object store fails readiness and pulls every pod out of the load balancer over something that does not stop it serving requests.

Why the migration is a Job, applied first

An API pod that starts against an un-migrated database answers relation does not exist to every request, so the migration has to finish before the new pods roll.

It is not an initContainer on the API Deployment, because that runs once per replica, concurrently. It is a Job, applied and waited for.

The Job's name carries the image tag, which is the part people are surprised by. A Job's pod template is immutable: a fixed name means the second deploy is rejected by the API server for changing a field that cannot change, and the deploy fails on its first step with a message about immutability rather than about anything you did.

There is no worker Deployment

A Grit API process starts its own asynq worker whenever Redis is reachable. There is no worker-only binary, so every API replica is also a queue consumer. Two things follow:

  • Scaling for HTTP load scales queue consumers with it. Usually what you want, occasionally not.
  • A slow or memory-hungry job runs inside a pod that is also serving requests.

If that is wrong for your workload, say so on the issue tracker: separating them needs a worker-only mode in the binary, which does not exist yet.

The secret is a template, and deliberately unreachable

secret.example.yaml holds placeholders and is not listed in kustomization.yaml, so apply -k cannot install it. It is the one file in the set that is dangerous when applied by accident: an API that starts with a placeholder signing key mints tokens anybody can forge and reports itself perfectly healthy.

Postgres, Redis and storage are yours

These manifests do not install a database, a cache or an object store. On a cluster those are nearly always a managed service or your own operator, and a generated single-replica Postgres with no backups looks production-ready and is not. The secret names yours instead.

Redis is not optional. The API starts its worker only when Redis answers, so without it no background job ever runs.

What you will want to change

  • ingress.yaml assumes an nginx ingress controller and cert-manager, and is only written when your .env names a real APP_URL. A development localhost writes no Ingress, because an Ingress nobody can reach is worse than none.
  • Resource requests and limits are a starting point, not a measurement. Run Pulse and a load test before you trust them.
  • api-hpa.yaml scales on CPU. Delete it to pin replicas.

Running more than one instance is the page that says what several copies of a Grit API share and what they still count separately. The manifests here assume you have read it: they set the same secret on every replica and run migrations once, which are two of the things that page is about.