November 14, 2026
A typical Django application usually has two parts:
Docker Compose lets you describe this entire system declaratively in a single compose.yaml:
services:
web:
build: .
command: gunicorn myproject.wsgi:application --bind 0.0.0.0:8000
depends_on:
- db
ports:
- "8000:8000"
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
postgres_data:
Why Compose Is Often the Right Choice
| Advantage | Why it matters |
|---|---|
| Low setup cost | New developers can start quickly |
| Simple networking | Django connects to db:5432 on the Compose network |
| Shared configuration | Application services are defined together |
| Persistent volumes | Local DB data survives container recreation |
| Fast feedback | Build, start, inspect logs, and debug with a small command set |
Compose also works well for integration tests, CI jobs, and small single-server deployments.
Don't migrate to Kubernetes just because it's popular. If one server is enough, planned downtime is acceptable, and manual recovery is manageable, Compose is likely the more economical choice.
The real question: have your availability, scaling, deployment, and recovery requirements outgrown the single-host model?
Compose can restart failed containers and even run multiple replicas in some setups — it's not incapable. The limitation is its operational model: there's no cluster-wide reconciliation or scheduler like Kubernetes has.
If Django service runs on one VM and that VM is down, restart policies won't bring it back on a different machine. If you need zero-downtime deployments, workload distribution across machines, or autoscaling, you'll end up bolting extra tooling onto Compose — and owning the coordination yourself.
Compose vs. Kubernetes
| Capability | Docker Compose | Kubernetes |
|---|---|---|
| Scheduling | Single Docker host | Schedules across cluster nodes |
| Recovery | Container-level restart policies | Controllers reconcile toward desired state |
| Rolling deployments | Needs extra tooling | Built into Deployments |
| Service discovery | Service names on Compose network | Services + cluster DNS |
| Autoscaling | Not built-in | Horizontal Pod Autoscaler + node autoscaling |
| Operations | Simple | More powerful, more complex |
Kubernetes brings real costs too: more YAML, networking concepts, RBAC, monitoring, cluster upgrades, infrastructure decisions.
Rule of thumb: Move to Kubernetes when you need its capabilities enough to justify the added operational complexity — not before.
Minimal Kubernetes knowledge required to deploy a Django app on it:
DJANGO_SETTINGS_MODULE).Example minimal Deployment + Service for the Django web app:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: web
image: myregistry/myapp:1.0.0
ports:
- containerPort: 8000
envFrom:
- configMapRef:
name: django-config
- secretRef:
name: django-secrets
---
apiVersion: v1
kind: Service
metadata:
name: myapp
spec:
selector:
app: myapp
ports:
- port: 80
targetPort: 8000
A practical migration path:
environment: values into ConfigMaps and Secrets.depends_on — Kubernetes has no native "wait for dependency" logic; use init containers or readiness probes instead.ClusterIP.Running stateful databases in Kubernetes is possible but adds responsibility:
| Option | Pros | Cons |
|---|---|---|
| Managed DB (RDS, Cloud SQL, etc.) | Backups, failover, patching handled for you | External dependency, cost |
| Self-hosted in Kubernetes (via StatefulSet / Operator) | Full control, everything in one cluster | You own backups, failover, upgrades, storage performance |
Recommendation: Unless you have strong operational reasons (compliance, cost at scale, multi-cluster portability), use a managed PostgreSQL service and keep Kubernetes focused on stateless workloads. If you must self-host, use a mature distributed storage provider like Longhorn, Ceph.
For anything that must survive pod rescheduling (media uploads, self-hosted DB data):
emptyDir or node-local storage for anything you can't afford to lose.apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: django-media
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Note: When use PersistentVolumeClaim (PVC), you must explicitly choose how Kubernetes handles your underlying data if your PVC is deleted. By default, deleting a PVC will completely destroy the cloud storage disk and erase all data.
Kubernetes relies on probes to know when a pod is ready and alive. Adjust this parameters based on application requirements.
readinessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 15
periodSeconds: 20
Deployments perform rolling updates using these checks: new pods come up and pass readiness checks before old pods are terminated, giving you zero-downtime deploys.
Horizontal scaling means to deploy more pods when needed. Kubernetes can scale your web pods automatically based on CPU or memory utilization:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
A typical pipeline:
myregistry/myapp:<git-sha>).kubectl apply steps
and make deployments auditable and reproducible.A pragmatic stack for a production Django app on Kubernetes:
| Stage | Tool |
|---|---|
| Local dev / small deployments | Docker Compose |
| Growing scale, multi-node, zero-downtime needs | Kubernetes |
| Database | Prefer managed, self-host only with an Operator |
| Deployment | GitOps (ArgoCD/Flux) over manual kubectl apply |
Bottom line: Start with Compose. Migrate to Kubernetes when your reliability and scaling requirements genuinely demand it — not because it's the industry trend.