From Docker Compose to Kubernetes: What Actually Changes in Production?

November 14, 2026


1. Why Docker Compose is Great for Starting

A typical Django application usually has two parts:

  • Django web app
  • PostgreSQL database

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?


2. Where Docker Compose Starts Becoming Limiting

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.


3. Minimal Kubernetes Concepts

Minimal Kubernetes knowledge required to deploy a Django app on it:

  • Pods – the smallest deployable unit; usually one container per pod.
  • Deployments – manage replica sets of pods, handle rolling updates and self-healing.
  • Services – stable network identity + load balancing for a set of pods (replaces Compose's name-based discovery).
  • ConfigMaps – non-secret configuration (e.g., DJANGO_SETTINGS_MODULE).
  • Secrets – sensitive values (DB passwords, API keys), base64-encoded, optionally encrypted at rest.
  • Ingress – HTTP(S) routing into the cluster, usually backed by an Ingress Controller (nginx, Traefik).

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

4. Migrating a Django Application to Kubernetes

A practical migration path:

  1. Create a Dockerfile — Kubernetes just schedules containers, it doesn't build docker images.
  2. Translate each Compose service into a Deployment + Service pair or a StatefulSet (database, if self-hosted).
  3. Externalize configuration — move environment: values into ConfigMaps and Secrets.
  4. Replace depends_on — Kubernetes has no native "wait for dependency" logic; use init containers or readiness probes instead.
  5. Replace volumes — map Compose named volumes to PersistentVolumeClaims.
  6. Do not expose the app externally — Use a Kubernetes Service of Type ClusterIP.
  7. Ingress - Use a Ingress controller (nginx, Traefik).
  8. Test rolling updates before relying on them in production.

5. PostgreSQL: Should It Run Inside Kubernetes?

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.


6. Persistent Storage in Kubernetes

For anything that must survive pod rescheduling (media uploads, self-hosted DB data):

  • Use PersistentVolumeClaims (PVCs) backed by your cloud provider's storage class.
  • Avoid emptyDir or node-local storage for anything you can't afford to lose.
  • For object storage needs (user uploads), prefer S3-compatible storage over PVCs — it scales better and avoids pod-to-volume binding constraints.
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.


7. Health Checks and Rolling Updates

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
  • Readiness probe — controls whether a pod receives traffic.
  • Liveness probe — controls whether Kubernetes restarts a stuck pod.

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.


8. Horizontal Scaling

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

9. CI/CD → Kubernetes Deployment

A typical pipeline:

  1. Build — build and tag the Docker image (myregistry/myapp:<git-sha>).
  2. Push — push to a container registry.
  3. Test — run migrations check, linting, unit tests against an ephemeral environment.
  4. Deploy — Tools like Helm, Kustomize, or ArgoCD/Flux (GitOps) remove manual kubectl apply steps and make deployments auditable and reproducible.

10. What I Would Use in a Real Production Environment

A pragmatic stack for a production Django app on Kubernetes:

  • Managed Kubernetes (EKS/GKE/AKS) — don't run your own control plane unless required.
  • Managed PostgreSQL (RDS/Cloud SQL) — outsource backups and failover.
  • Ingress + cert-manager — automated TLS via Let's Encrypt.
  • Helm charts for packaging, ArgoCD for GitOps-based deployment.
  • Horizontal Pod Autoscaler for web pods.
  • Prometheus + Grafana for metrics, Loki or managed logging for logs.
  • PodDisruptionBudgets to avoid all replicas going down during node maintenance.

Summary

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.