A tiny Django app with four routes for Kubernetes probe practice:
/— Index/startup— forstartupProbe/live— forlivenessProbe/ready— forreadinessProbe(optionally delayed viaREADINESS_DELAYenv var)
# 1) Build and run with Docker
docker build -t dj-k8s-practice:latest .
docker run --rm -p 8000:8000 -e DJANGO_SECRET_KEY=dev-secret -e DJANGO_DEBUG=1 -e READINESS_DELAY=0 dj-k8s-practice:latest
# Visit http://localhost:8000/, /startup, /live, /readyOr with docker-compose:
docker compose up --buildDJANGO_SECRET_KEY(required in prod) — Django secret key.DJANGO_DEBUG(0/1, default0)ALLOWED_HOSTS(comma-separated, default*)READINESS_DELAY(seconds; default0). If set (e.g.,30),/readywill return 503 until the delay has passed since the process started, useful for practicing readiness probes.
-
(Optional) Create a secret for the Django key:
kubectl apply -f k8s/secret.example.yaml
Edit the base64 value or create your own Secret.
-
Deploy:
kubectl apply -f k8s/deployment.yaml kubectl apply -f k8s/service.yaml
-
Port-forward the service:
kubectl port-forward svc/dj-k8s-practice 8000:80
- startupProbe → GET
/startup - livenessProbe → GET
/live - readinessProbe → GET
/ready(honorsREADINESS_DELAY)
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export DJANGO_SECRET_KEY=dev-secret
export DJANGO_DEBUG=1
python manage.py migrate
python manage.py runserver 0.0.0.0:8000dj-k8s-practice/
├── config/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── core/
│ ├── __init__.py
│ ├── apps.py
│ ├── health.py
│ ├── urls.py
│ └── views.py
├── k8s/
│ ├── deployment.yaml
│ ├── secret.example.yaml
│ └── service.yaml
├── manage.py
├── requirements.txt
├── Dockerfile
├── docker-compose.yml
├── .dockerignore
└── .gitignore