Tutorial 9: Run it on Kubernetes
Verified against gamewarden v0.2.0 (see the changelog) on kind v0.33.0
(Kubernetes v1.37.0) with Docker 29.9.3. About 25 minutes.
The script 09-run-it-on-kubernetes.sh runs every command below
against a local cluster. Unlike the other tutorials it needs a Kubernetes cluster, so it is not part
of make guides-check. It runs with make k8s-tutorial-check.
Tutorial 6 ran the gateway with Postgres and Redis in Docker Compose. Here you
install the Helm chart in deploy/helm/gamewarden on a local Kubernetes cluster, with two gateway
replicas, and play the city game through it. Then you upload a new manifest, delete a pod and
restart the deployment, and see that nothing was lost.
Prerequisites
Section titled “Prerequisites”- Docker with Compose v2, the repository
(
git clone https://github.com/Moustafa-Elgammal/gamewarden && cd gamewarden), andmake. - Nothing else on your machine. kind (Kubernetes in Docker),
kubectlandhelmrun in thek8stools container (Dockerfile targetk8s). It reaches your Docker through its socket, so kind creates the cluster’s node as a container next to your others.
Start a shell in that container with a fresh cluster:
make k8s-shellmake k8s-shell runs scripts/kind-run.sh. It creates a kind cluster called gamewarden-t09
(set KIND_CLUSTER for another name), points kubectl at it, and deletes that cluster, and only
that one, when you leave the shell. It refuses to start if a cluster with that name already exists.
The kubeconfig lives in the container, so your own ~/.kube/config is never changed. Every command
below runs in this shell. Check which cluster you are about to use:
kubectl config current-contextkubectl get nodesThe context is kind-gamewarden-t09. make k8s-tutorial-check does the same and runs the script
in place of the shell. The script refuses to run unless the context is kind-kind, or the one in
K8S_CONTEXT, which scripts/kind-run.sh sets. To run it against a kind cluster of your own, with
your own kind, kubectl and helm, use K8S_CONTEXT=kind-<name> bash docs/tutorials/09-run-it-on-kubernetes.sh.
Do not point this at a cluster you care about: the tutorial uses its own namespace,
gamewarden-tutorial, and deletes it at the end, but it also loads two images into the cluster’s
nodes. (On Docker Desktop’s built in Kubernetes, follow
tutorial 11 instead.)
What you are building
Section titled “What you are building”flowchart LR Agent["Your machine<br/>(curl, studiocall)"] -->|kubectl port-forward| Svc["Service gamewarden"] Svc --> G1["gateway pod 1"] Svc --> G2["gateway pod 2"] G1 & G2 --> R[("Redis<br/>limits, caps")] G1 & G2 --> P[("Postgres<br/>grants, manifests, audit")] G1 & G2 -->|signed calls| B["city backend"]Everything lives in one namespace. Postgres and Redis are small dev-only deployments
(examples/tutorials/k8s/data.yaml) with their data on an emptyDir: in production use managed
services. The demo backend is the same fake city as in the other tutorials.
1. Build the images and make the cluster see them
Section titled “1. Build the images and make the cluster see them”export TAG=$(date +%s) # a new tag every time, so the cluster never keeps using an older builddocker build --target gateway -t gamewarden:$TAG .docker build --target city-backend -t city-backend:$TAG .A kind cluster has its own image store, separate from Docker’s, so load the images into it:
kind load docker-image gamewarden:$TAG city-backend:$TAG --name gamewarden-t09(Use your cluster’s name if you set KIND_CLUSTER.) The manifests use
imagePullPolicy: IfNotPresent, so Kubernetes uses the loaded image and never looks for
gamewarden:<tag> on a public registry. A cloud cluster pulls from a registry instead: push the
images there and set image.repository and image.tag. On Docker Desktop’s Kubernetes no loading
is needed, see tutorial 11.
2. The namespace and the Secret
Section titled “2. The namespace and the Secret”The chart never takes a secret inline. You create a Secret and name it with existingSecret. Keys:
signing-secret (required), admin-secret and postgres-url.
kubectl apply -f examples/tutorials/k8s/namespace.yaml
SIGNING_SECRET=$(openssl rand -hex 24)ADMIN_SECRET=$(openssl rand -hex 24)kubectl -n gamewarden-tutorial create secret generic gamewarden-credentials \ --from-literal=signing-secret="$SIGNING_SECRET" \ --from-literal=admin-secret="$ADMIN_SECRET" \ --from-literal=postgres-url='postgres://gamewarden:gamewarden-dev@postgres:5432/gamewarden?sslmode=disable'The signing secret does two jobs. Your studio backend signs player calls with it (the studio key,
studio-1), and the gateway signs its calls to the game backend with it. The admin secret signs
manifest uploads and is a different key on purpose.
3. Postgres, Redis and the backend
Section titled “3. Postgres, Redis and the backend”kubectl apply -f examples/tutorials/k8s/data.yamlsed "s#city-backend:tutorial#city-backend:$TAG#" examples/tutorials/k8s/backend.yaml | kubectl apply -f -kubectl -n gamewarden-tutorial rollout status deploy/postgres deploy/redis deploy/city-backend --timeout=180sThe sed puts this run’s image tag into the backend manifest, the same tag you built above.
The backend reads the same Secret, so it can verify the gateway’s signatures.
4. Install the chart
Section titled “4. Install the chart”The values file examples/tutorials/k8s/values.yaml holds the few settings that differ from the
defaults. Read it first. The important ones:
config.publicURLishttp://127.0.0.1:18209, the address you will use throughport-forward. Tokens are bound to it. In production it is your public HTTPS URL.config.backendAllowPrivate: true, because the backend is a cluster address, which counts as private. The gateway refuses private addresses unless you say so.config.redisAddrturns on the shared policy store, so limits hold across both replicas.config.manifestPoll: 2smakes a manifest upload reach every replica within seconds.
The manifest itself comes from the repository’s demo, as a file, not from the values:
helm install gamewarden deploy/helm/gamewarden --namespace gamewarden-tutorial \ -f examples/tutorials/k8s/values.yaml \ --set image.tag=$TAG \ --set-file manifest=examples/city/manifest.yaml \ --wait --timeout 180skubectl -n gamewarden-tutorial get pods -l app.kubernetes.io/name=gamewardenNAME READY STATUS RESTARTS AGEgamewarden-7c9f6d8b5-4xk2p 1/1 Running 0 20sgamewarden-7c9f6d8b5-m8wzt 1/1 Running 0 20s--wait returned because both pods passed their readiness probe, which asks /readyz on the ops
port. The gateway is ready only when it can reach Redis and Postgres.
5. Health, readiness and metrics
Section titled “5. Health, readiness and metrics”The ops port (9090 in the chart) is not on the public Service. It has its own Service, for probes and for Prometheus. Reach it from your machine:
kubectl -n gamewarden-tutorial port-forward svc/gamewarden-ops 19209:9090 &curl -s http://127.0.0.1:19209/readyzcurl -s http://127.0.0.1:19209/metrics | grep -E '^gamewarden_build_info|^go_goroutines'For a real cluster, set serviceMonitor.enabled if you run the Prometheus Operator, and import
deploy/grafana/ and deploy/prometheus/alerts.yaml (see the runbook).
6. Play the game through the cluster
Section titled “6. Play the game through the cluster”Build the two helper programs for your own system. They run in Docker, so you need no Go installation:
docker compose build devdocker compose run --rm --no-deps -e GOOS=$(uname -s | tr A-Z a-z) -e GOARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/') \ -e CGO_ENABLED=0 dev go build -o .tutorial-tmp/bin/ ./examples/studiocall ./examples/oauthclientexport PATH="$PWD/.tutorial-tmp/bin:$PATH"Reach the gateway itself and link a player, exactly as in tutorial 4. The
studio backend (here, studiocall) signs a ticket request with the studio key:
kubectl -n gamewarden-tutorial port-forward svc/gamewarden 18209:80 &GW=http://127.0.0.1:18209
TICKET=$(GAMEWARDEN_SIGNING_SECRET=$SIGNING_SECRET studiocall --url $GW --key-id studio-1 \ --player alice --expect 201 POST /v1/studio/link-tickets | sed 's/.*"ticket":"\([^"]*\)".*/\1/')oauthclient --url $GW --ticket "$TICKET" --scope operatorThe last command prints the tokens. Put the access token in ACCESS and call a tool:
ACCESS=<the access_token value>curl -s -H "Authorization: Bearer $ACCESS" -H 'Content-Type: application/json' \ -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2025-06-18' \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_city_state","arguments":{}}}' \ $GW/mcpThe answer is the city’s state. The call crossed the Service to one of the two gateway pods, passed the policy checks with limits kept in Redis, was signed, and reached the backend pod. Selling something works too, and shows up in the activity feed:
curl -s -H "Authorization: Bearer $ACCESS" -H 'Content-Type: application/json' \ -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2025-06-18' \ -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"sell_resource","arguments":{"resource":"food","quantity":5}}}' \ $GW/mcpGAMEWARDEN_SIGNING_SECRET=$SIGNING_SECRET studiocall --url $GW --key-id studio-1 \ --player alice --expect 200 GET '/v1/studio/activity?limit=5'7. Change the manifest while it runs
Section titled “7. Change the manifest while it runs”Upload the smaller manifest with the admin key. It is stored in Postgres, so both replicas serve it
within manifestPoll:
GAMEWARDEN_ADMIN_SECRET=$ADMIN_SECRET studiocall --url $GW --key-id admin-1 \ --secret-env GAMEWARDEN_ADMIN_SECRET --player ci --expect 201 \ --content-type application/yaml --body-file examples/tutorials/city-lite.yaml PUT /v1/studio/manifestList the tools a few times. sell_resource is gone, whichever pod answers. The Helm value
manifest is only the seed for an empty store. After the first upload the store is the source of
truth, which is why a helm upgrade does not undo an upload.
8. Kill a pod
Section titled “8. Kill a pod”POD=$(kubectl -n gamewarden-tutorial get pods -l app.kubernetes.io/name=gamewarden -o jsonpath='{.items[0].metadata.name}')kubectl -n gamewarden-tutorial delete pod "$POD"kubectl -n gamewarden-tutorial rollout status deploy/gamewardenKubernetes starts a new pod, and the Service sends traffic only to pods that are ready. Your token still works and the uploaded manifest is still the active one, because both live in Postgres, not in the pod. Restart your port forward first, since it was attached to the pod you deleted.
Then restart the whole deployment. The chart uses maxUnavailable: 0 and a disruption budget of
one, so there is always a ready pod:
kubectl -n gamewarden-tutorial rollout restart deploy/gamewardenkubectl -n gamewarden-tutorial rollout status deploy/gamewardenkubectl -n gamewarden-tutorial get pdb9. Clean up
Section titled “9. Clean up”helm uninstall gamewarden --namespace gamewarden-tutorialkubectl delete namespace gamewarden-tutorialStop the port forwards (kill %1 %2), then leave the shell with exit. That deletes the kind
cluster.
In production
Section titled “In production”- Use
existingSecretwith sealed-secrets or external-secrets, never--from-literalon a shared machine. AddkeyFilesSecretfor key rotation without a restart (tutorial 6). - Terminate TLS at an Ingress (
ingress.enabled) and setconfig.publicURLto that HTTPS address. - Set
config.clientIPHeaderonly behind a proxy that overwrites it. - Point
redisAddrandpostgres-urlat managed services. Without Redis each replica counts limits on its own. Without Postgres, grants and manifests are lost when a pod goes. - Start with
config.maxScope: coach, then raise it tooperator. - Turn on
networkPolicyandserviceMonitor, and import the dashboards and alerts.
What you learned
Section titled “What you learned”- The chart takes everything secret from one Secret you create, and refuses to install without it.
- Two replicas share limits through Redis and state through Postgres, so a pod can die without losing grants, tokens or the active manifest.
/readyzon the ops port decides whether a pod gets traffic.- A manifest upload changes the running tools without a rollout.
Tutorial 6: Go live covers key rotation and the admin key in more depth. The runbook has the production checklist, alerts and what to do when Redis or Postgres is down.