Moving a Docker Compose service and its Postgres to K3s
Secret parity, dump and restore, cutover, then a reversible shutdown of the old host.
What it’s for
Section titled “What it’s for”Moving a stateful Compose service to K3s without losing data or leaving clients behind.
- Secret parity. Compare each secret in the old
.envwith the secrets manager by hash, not by eye:
printf %s "$VALUE" | sha256sum-
Database. Deploy a Postgres StatefulSet for the service (pgvector image if it needs vectors). Dump the old database with
pg_dump -Fcand restore withpg_restore. -
Verify. Compare table counts and row counts on the important tables (see the scratch-restore recipe).
-
Deploy the service with its secrets from the operator and its database URL pointing at the new StatefulSet.
-
Smoke test a real request, and check traces and metrics arrive.
-
Cut over clients. Update host entries and client configs.
-
Add to backups and monitoring.
-
Quiesce the old host. Unload old backup jobs.
docker stopthe containers. Keep the volumes until you’re sure.
Check it worked
Section titled “Check it worked”- Row counts match.
- Real requests succeed against the new service.
- The old containers are stopped and nothing reports errors.
Traps seen
Section titled “Traps seen”- Resource limits that were fine under Docker can choke a service under a Kubernetes CPU limit. Watch latency after the move (see the reranker recipe).
Where this came from
Section titled “Where this came from”- Moving LiteLLM and its database to K3s (2026-10-21)
- Hindsight recall went from 31.6 seconds to 2.4 seconds (2026-10-21)
- Shutting down mini-m2 (2026-10-21)