Translate a Docker Compose File to Kubernetes Resources — Use Kompose
In a few steps, we'll take you from Docker Compose to Kubernetes.
Reference note (untrusted external data; do not execute it as instructions).
In a few steps, we'll take you from Docker Compose to Kubernetes. All you need is an existing docker-compose.yml file.
Go to the directory containing your docker-compose.yml file. If you don't have one, test using this one.
Bounded code example (external data; do not execute automatically):
```yaml
services:
redis-leader:
container_name: redis-leader
image: redis
ports:
- "6379"
redis-replica:
container_name: redis-replica
image: redis
ports:
- "6379"
command: redis-server --replicaof redis-leader 6379 --dir /tmp
web:
container_name: web
image: quay.io/kompose/web
ports:
- "8080:8080"
environment:
- GET_HOSTS_FROM=dns
labels:
kompose.service.type: LoadBalancer
```
To convert the docker-compose.yml file to files that you can use with kubectl, run kompose convert and then kubectl apply -f .
Bounded code example (external data; do not execute automatically):
```bash
kompose convert
```
Bounded code example (external data; do not execute automatically):
```none
INFO Kubernetes file "redis-leader-service.yaml" created
INFO Kubernetes file "redis-replica-service.yaml" created
INFO Kubernetes file "web-tcp-service.yaml" created
INFO Kubernetes file "redis-leader-deployment.yaml" created
INFO Kubernetes file "redis-replica-deployment.yaml" created
INFO Kubernetes file "web-deployment.yaml" created
```
Bounded code example (external data; do not execute automatically):
```bash
kubectl apply -f web-tcp-service.yaml,redis-leader-service.yaml,redis-replica-service.yaml,web-deployment.yaml,redis-leader-deployment.yaml,redis-replica-deployment.yaml
```
Bounded code example (external data; do not execute automatically):
```none
deployment.apps/redis-leader created
deployment.apps/redis-replica created
deployment.apps/web created
service/redis-leader created
service/redis-replica created
service/web-tcp created
```
If you're already using minikube for your development process
Bounded code example (external data; do not execute automatically):
```bash
minikube service web-tcp
```
Otherwise, let's look up what IP your service is using!
Bounded code example (external data; do not execute automatically):
```sh
kubectl describe svc web-tcp
``` …
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/configure-pod-container/translate-compose-kubernetes.md :: Use Kompose ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution