forked from ungleich-public/dynamicweb
3 KiB
3 KiB
Deploying dynamicweb on Kubernetes
k8s/dynamicweb.yaml describes what runs: the web app, the Celery worker, Redis, a volume for uploaded media, and an Ingress. PostgreSQL 18 is not included: use your own database and point the app at it.
Tested on a local
kindcluster with a scratch Postgres (migrate Job, then web and the admin answer 200). Not tested on your cluster, ingress controller or real data.
Steps
- Push the image (build it once, from the repo):
docker compose build docker tag dynamicweb:latest <registry>/dynamicweb:<version> docker push <registry>/dynamicweb:<version> - Make an env file from
.env.dockerwith your real values. Change at least:
plus your OpenNebula, LDAP, Stripe, email and reCAPTCHA values. Leave the Redis URLs alone; the manifest creates a service calledDEBUG=False SEED_DUMMY_DATA=False DJANGO_SECRET_KEY=<a long random string> POSTGRES_HOST=<your database host> # and POSTGRES_PORT/DB/USER/PASSWORD BEHIND_TLS_PROXY=True # TLS ends at the ingress UNGLEICH_SITE_CONFIGS=<your real JSON>redis. - Store it as a Secret:
kubectl create secret generic dynamicweb --from-env-file=<your env file> - Edit the manifest: your image name (it appears three times) and the Ingress hosts (one rule
for each domain, with
www.variants). SetingressClassNameto your controller. - Migrate, then start. If you have old data, restore it into the empty database first (for
example
psql -h <host> -U <user> <db> < dump.sql). Then:
Thekubectl apply -f k8s/dynamicweb.yaml kubectl logs -f job/dynamicweb-migrate # takes a few minutes; ends when the Job completes kubectl rollout restart deploy/dynamicweb-web kubectl logs -f deploy/dynamicweb-web # ready at "Listening at"dynamicweb-migrateJob runs the migrations once. The web pods don't migrate, so restart them after the Job completes (a web pod that started earlier serves errors until you do). - Check:
curl -I -H 'Host: ungleich.ch' http://<ingress-address>/en-us/returns 200. Admin is at/en-us/admin/login/on any site's address.
Good to know
- Scaling:
kubectl scale deploy/dynamicweb-web --replicas=2, with the media volume changed toReadWriteManyso every pod sees the same uploads. - Ingress must keep the original
Hostheader (the default). The site is chosen from the host, and every domain must be inUNGLEICH_SITE_CONFIGSand inALLOWED_HOSTS(dynamicweb/settings/prod.pylists the current ones). - Updating: push a new image tag, change the image in the manifest, delete the old Job
(
kubectl delete job dynamicweb-migrate) and apply again, then restart web. - Logs:
kubectl logs deploy/dynamicweb-webandkubectl logs deploy/dynamicweb-celery. - Don't name a Service
postgreswithoutenableServiceLinks: false. Kubernetes would injectPOSTGRES_PORT=tcp://...and the app crashes. The manifest already sets it on every pod.