Docs / Migration Guides / Docker Compose to Kubernetes with Kompose

Docker Compose to Kubernetes with Kompose

By Admin · Mar 15, 2026 · Updated Apr 23, 2026 · 438 views · 2 min read

What is Kompose?

Kompose is a tool that converts Docker Compose files into Kubernetes resource manifests. It bridges the gap between development (Docker Compose) and production (Kubernetes) environments, automating the creation of Deployments, Services, PersistentVolumeClaims, and ConfigMaps.

Installing Kompose

# Linux
curl -L https://github.com/kubernetes/kompose/releases/download/v1.34.0/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv kompose /usr/local/bin/

# Verify
kompose version

Basic Conversion

# Given docker-compose.yml:
version: "3.8"
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - web-data:/usr/share/nginx/html
  api:
    build: ./api
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/myapp
    depends_on:
      - db
  db:
    image: postgres:16
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  web-data:
  db-data:

# Convert to Kubernetes manifests
kompose convert

# This generates:
# web-deployment.yaml, web-service.yaml
# api-deployment.yaml, api-service.yaml
# db-deployment.yaml, db-service.yaml
# web-data-persistentvolumeclaim.yaml
# db-data-persistentvolumeclaim.yaml

Advanced Options

# Output as Helm chart
kompose convert -c

# Output single file
kompose convert -o k8s-manifests.yaml

# Use specific controller type
kompose convert --controller deployment  # default
kompose convert --controller daemonset
kompose convert --controller statefulset

# Generate with replicas
kompose convert --replicas 3

Manual Adjustments

# Kompose output often needs tuning:
# 1. Add resource limits
resources:
  requests:
    memory: "128Mi"
    cpu: "250m"
  limits:
    memory: "512Mi"
    cpu: "1000m"

# 2. Add health checks
livenessProbe:
  httpGet:
    path: /health
    port: 3000
  initialDelaySeconds: 30

# 3. Use Secrets for passwords (not plain env vars)
# 4. Configure Ingress for external access
# 5. Set proper storage classes for PVCs

Deploy to Kubernetes

# Apply generated manifests
kubectl apply -f .

# Or deploy directly
kompose up

# Check status
kubectl get pods,svc,pvc

# Cleanup
kompose down
# Or: kubectl delete -f .

Best Practices

  • Review and customize generated manifests before deploying
  • Convert environment variables with secrets to Kubernetes Secrets
  • Add resource limits to prevent resource contention
  • Use StatefulSets for databases instead of Deployments
  • Configure proper health checks for all services
  • Set up Ingress controllers for HTTP routing

Was this article helpful?