How to Convert a Docker Compose File to Kubernetes Manifests Using Kompose
Many of us use Docker for local development, but when it’s time to run containers on Kubernetes, converting your setup can seem daunting. Kompose makes this transition easy by converting your docker-compose.yml
into Kubernetes manifests.
Below are the latest steps to get your services running on Kubernetes:
1. Install Kompose (Latest Version)
On Mac (using Homebrew):
brew install kompose
Or download the latest release manually:
curl -L https://github.com/kubernetes/kompose/releases/latest/download/kompose-darwin-amd64 -o kompose
chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose
2. Prepare Your Docker Compose File
- Build and push your Docker images to a remote registry.
-
Update your
docker-compose.yml
so that each service uses the image URL from your registry (not a local build context).
Example docker-compose.yml
:
version: "3"
services:
mythical-requester:
image: <REMOTE-IMAGE>
ports:
- "4001:4001"
environment:
- NAMESPACE=production
- LOGS_TARGET=http://loki:3100/loki/api/v1/push
- TRACING_COLLECTOR_HOST=agent
- TRACING_COLLECTOR_PORT=4317
- OTEL_EXPORTER_OTLP_TRACES_INSECURE=true
- OTEL_RESOURCE_ATTRIBUTES=ip=1.2.3.4
mythical-server:
image: <REMOTE-IMAGE>
ports:
- "4000:4000"
- "80:80"
depends_on:
- mythical-database
environment:
- NAMESPACE=production
- LOGS_TARGET=http://loki:3100/loki/api/v1/push
- TRACING_COLLECTOR_HOST=agent
- TRACING_COLLECTOR_PORT=4317
- OTEL_EXPORTER_OTLP_TRACES_INSECURE=true
- OTEL_RESOURCE_ATTRIBUTES=ip=1.2.3.5
mythical-recorder:
image: <REMOTE-IMAGE>
ports:
- "4002:4002"
environment:
- NAMESPACE=production
- LOGS_TARGET=http://loki:3100/loki/api/v1/push
- TRACING_COLLECTOR_HOST=agent
- TRACING_COLLECTOR_PORT=4317
- OTEL_EXPORTER_OTLP_TRACES_INSECURE=true
- OTEL_RESOURCE_ATTRIBUTES=ip=1.2.3.5
3. Convert Docker Compose to Kubernetes Manifests
Run the following command in the directory containing your docker-compose.yml
:
kompose convert
Kompose will generate Kubernetes YAML files for each service, typically creating both a deployment
and a service
manifest per service.
4. Deploy to Kubernetes
-
Move all generated YAML files to a folder (e.g.,
deployment/
):
mkdir deployment mv *.yaml deployment/
Connect to your Kubernetes cluster (ensure
kubectl
is configured).-
Apply all manifests:
kubectl apply -f deployment/
-
Check your pods:
kubectl get pods
Congratulations!
Your Docker Compose services are now running on your Kubernetes cluster.
References:
Top comments (0)