Docker Compose is incredible for local development and early-stage deployments. A single YAML file, quick spin-up times, and zero complex orchestration make it ideal for getting projects off the ground.
However, as your app grows, Docker Compose hits a ceiling. Zero-downtime deployments become difficult, multi-node scaling requires manual work, and automated self-healing is virtually non-existent.
When engineering teams realize it is time to move to Kubernetes, they usually fall into one of two traps: they either freeze out of fear of breaking production, or they burn weeks rewriting every manifest from scratch.
There is a saner middle path. By following a structured process—audit, convert, adapt, and validate—you can migrate safely without losing weeks of developer time.
Step 1: Generate a Baseline with Kompose
Instead of writing Kubernetes manifests from a blank editor, use kompose to generate an initial working draft. Kompose is an official Kubernetes project designed to translate docker-compose.yml files directly into Kubernetes resources.
Consider a simple application stack in Docker Compose:
# docker-compose.yml version: '3.8' services: web: image: myapp/web:v1.2.0 ports: - "8080:8080" environment: - DATABASE_URL=postgres://user:pass@db:5432/appdb depends_on: - db db: image: postgres:15-alpine volumes: - db_data:/var/lib/postgresql/data volumes: db_data: You can convert this configuration into Kubernetes resources using the command line:
kompose convert -f docker-compose.yml This command generates output files for your Deployments, Services, and PersistentVolumeClaims. However, treat this output as a rough draft—never deploy raw Kompose output directly to production.
Step 2: Refine Networking and Service Discovery
In Docker Compose, services communicate directly using container names on shared networks. In Kubernetes, pods are ephemeral, and IP addresses change frequently.
While Kompose generates standard Service manifests, you need to adapt them to match Kubernetes networking best practices:
- Internal Routing: Convert internal services (like databases or caches) into
ClusterIPservices so they remain unreachable from the outside world. - Ingress Management: Instead of exposing ports directly using
NodePortorLoadBalancerfor every container, configure a singleIngresscontroller (such as NGINX or Traefik) to handle incoming HTTP/HTTPS traffic.
Step 3: Move Secrets and Configure Storage
Docker Compose often passes secrets as plain environment variables inside the Compose file or a local .env file. Leaving credentials hardcoded in production manifests is a serious security risk.
- Extract Secrets: Move sensitive credentials (API keys, database passwords) into native Kubernetes
Secretobjects, and store non-sensitive settings insideConfigMapmanifests. - Decouple Storage: Local bind mounts do not work cleanly on multi-node Kubernetes clusters. Reconfigure your stateful services to use proper
PersistentVolumeClaim(PVC) definitions tied to a managed cloud storage class.
Here is an example of an adapted Kubernetes Deployment manifest with secret references and proper resource definitions:
apiVersion: apps/v1 kind: Deployment metadata: name: web spec: replicas: 2 selector: matchLabels: app: web template: metadata: labels: app: web spec: containers: - name: web image: myapp/web:v1.2.0 ports: - containerPort: 8080 env: - name: DATABASE_URL valueFrom: secretKeyRef: name: db-credentials key: database-url resources: requests: memory: "128Mi" cpu: "250m" limits: memory: "512Mi" cpu: "500m" livenessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 15 periodSeconds: 20 Step 4: Add Resource Limits and Health Checks
Docker Compose rarely enforces CPU or memory limits by default. In Kubernetes, running containers without defined limits can lead to cluster instability. A single memory leak can cause nodes to run out of memory and terminate critical system processes.
Always explicitly state requests (what the pod is guaranteed) and limits (the maximum the pod can consume).
Additionally, configure explicit livenessProbe and readinessProbe blocks. Kubernetes uses these probes to determine when to restart failing containers and when a new pod is ready to accept live user traffic.
A Practical Timeline
For a medium-sized application (3 to 6 services), budget 2 to 4 weeks for the transition:
- Week 1: Audit your existing Compose files, separate secrets, and generate baseline manifests using
kompose. - Week 2: Adapt manifests by adding storage claims, Ingress rules, resource limits, and health checks.
- Week 3–4: Deploy to a staging cluster, perform load tests, verify automated failovers, and execute a controlled cutover.
By following this pragmatic path, you avoid the trap of endless rewrites while building a secure, reliable Kubernetes foundation that runs smoothly without constant intervention.
About me
Tanmay builds AI agents and automation for businesses and is open to freelance projects. Feel free to connect with Tanmay on LinkedIn.

