forked from ungleich-public/dynamicweb
2.6 KiB
2.6 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.
Not tested on a cluster. The image itself is tested with
docker compose(see DOCKER.md).
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 twice) and the Ingress hosts (one rule for
each domain, with
www.variants). SetingressClassNameto your controller. - Deploy:
The first start runs the database migrations, so it takes a few minutes.kubectl apply -f k8s/dynamicweb.yaml kubectl logs -f deploy/dynamicweb-web # ready at "Listening at" - 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
- Run one web replica first. Each web pod migrates the database when it starts. After the first
start you can scale (
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 and apply it again.
- Logs:
kubectl logs deploy/dynamicweb-webandkubectl logs deploy/dynamicweb-celery. - Optional hardening: run the migrations once as a Job instead of in every pod. Use a Job with
env: ROLE=migrate, and addRUN_MIGRATIONS=Falseto the web Deployment.