Docker to Kubernetes manifests converter

Turn a docker run command or a docker-compose.yml into Kubernetes manifests.

loading Docker to Kubernetes manifests converter
About this tool

What does converting Docker to Kubernetes do?

You have a container that works with docker run or a docker-compose.yml, and now it has to run on Kubernetes. A cluster does not read either format. It wants objects: a Deployment that keeps the pods running, a Service that exposes the port, a ConfigMap or Secret for the environment, and a PersistentVolumeClaim for data. Writing them by hand is slow and full of small traps, such as a selector that must match the pod labels. This converter reads your command or compose file and writes those manifests.

For each container you get a Deployment and a Service. Plain environment variables go to a ConfigMap, and names that look like secrets (passwords, tokens, keys) go to a Secret. A named volume becomes a PersistentVolumeClaim, and a bind mount becomes a hostPath volume with a warning. Memory and CPU limits are written in Kubernetes units, so --memory 256m becomes 256Mi and --cpus 0.5 becomes 500m. Entrypoint and command map to command and args, healthchecks to probes, and user to runAsUser. Everything is written in apply order, so one kubectl apply -f works.

Some Docker ideas do not exist in Kubernetes, and the tool says so: depends_on, networks, restart policies that are not always, logging drivers and ulimits. It runs in your browser. Your commands and compose files, which often contain passwords, are not uploaded. Treat the output as a good first draft and review it before you apply it to a real cluster. If you start from a compose file, check it first with the Docker Compose validator.

How to convert Docker to Kubernetes manifests

  1. Paste a docker run command or a compose file in the box. It opens with a docker run example (an nginx container with a port, two variables, a volume and limits), so you see the result at once. Both formats are detected for you.
  2. Set the options above the box: namespace, replicas, Service type (ClusterIP, NodePort or LoadBalancer), how to write environment variables (ConfigMap and Secret, or Variables in the Deployment), volume size, and Write kustomization.yaml.
  3. Read the output. With the default options it is one file with all the objects, separated by ---. With kustomization.yaml turned on, you get one file per object plus the kustomization, and a Generated files selector lets you switch between them.
  4. Read the notices under the result. Yellow ones need attention, for example a secret that ends up in a file you might commit.
  5. Copy the result, or download the file you are looking at.

To tidy or check the YAML afterwards, use the YAML formatter and the YAML validator. If you start from a compose file, the reverse path is the docker run to compose converter.

Examples

The default example

Input:

docker run -d --name web -p 8080:80 \
  -e APP_ENV=production -e DB_PASSWORD=change-me \
  -v site-data:/usr/share/nginx/html \
  --memory 256m --cpus 0.5 --restart always \
  nginx:1.27

Output, one file with five objects. DB_PASSWORD goes to the Secret and APP_ENV to the ConfigMap. The warning says that a Secret is only base64 in the cluster, so keep the file out of git:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: site-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: web-config
  labels:
    app: web
data:
  APP_ENV: production
---
apiVersion: v1
kind: Secret
metadata:
  name: web-secret
  labels:
    app: web
type: Opaque
stringData:
  DB_PASSWORD: change-me
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      volumes:
        - persistentVolumeClaim:
            claimName: site-data
          name: vol-1
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - containerPort: 80
          envFrom:
            - configMapRef:
                name: web-config
            - secretRef:
                name: web-secret
          resources:
            limits:
              cpu: 500m
              memory: 256Mi
          volumeMounts:
            - name: vol-1
              mountPath: /usr/share/nginx/html
---
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    app: web
spec:
  selector:
    app: web
  ports:
    - name: p80
      port: 8080
      targetPort: 80

The Service publishes port 8080, as in -p 8080:80, and sends it to container port 80.

Namespace, replicas, NodePort and kustomization

With namespace shop, 3 replicas, Service type NodePort, volume size 5Gi and Write kustomization.yaml turned on, the same command gives four files. The first is:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: shop
resources:
  - pvc-site-data.yaml
  - deployment-web.yaml
  - service-web.yaml

The Service file now looks like this, and the Deployment has replicas: 3:

apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: shop
  labels:
    app: web
spec:
  type: NodePort
  selector:
    app: web
  ports:
    - name: p80
      port: 8080
      targetPort: 80

Apply the folder with kubectl apply -k ..

Variables inside the Deployment

With Variables in the Deployment, the ConfigMap and Secret disappear and the container gets an env list. Use this for a quick test, not for real passwords:

          env:
            - name: APP_ENV
              value: production
            - name: DB_PASSWORD
              value: change-me

Common errors and how to fix them

  • This is not valid YAML (line 3, column 5): the compose file has an indentation or quote error. The message gives the position and the reason.
  • Paste a docker run command, or a compose file that starts with services:: the text is a list or a single value.
  • No services found: add a services: section, or paste a docker run command.
  • The docker run command could not be read: a docker run command must start with docker run and end with the image name. docker run -e A=1 has no image.
  • This service is built from source, and a cluster cannot build it: build and push the image yourself, then write its registry name where the manifest has the image.
  • This service has no image: the manifest has <image> where the image name goes. Fill it in.
  • The bind mount became a hostPath volume: that ties the pod to one node. A PersistentVolumeClaim is the usual choice.
  • The user is a name: Kubernetes needs a numeric user ID in runAsUser.
  • The value holds a variable reference: Kubernetes does not read your shell or a .env file, so write the final value.

Frequently asked questions

How do I convert docker-compose to Kubernetes?

Paste the compose file and read the result. Each service gets a Deployment and a Service. Apply the file with kubectl apply -f manifests.yaml.

Is the output ready for production?

Treat it as a starting point. It is a faithful translation of what Docker had, not a design for your cluster. Review replicas, probes, resource requests, storage classes and how secrets are managed.

Are my secrets safe in the generated Secret?

A Kubernetes Secret is only base64-encoded unless the cluster encrypts it. The tool warns you. Keep the file out of git or use a secrets tool.

What happens to depends_on and networks?

Neither exists in Kubernetes. Pods start together and reach each other by Service name on one flat network. Make the app retry its connections, or add an init container that waits.

How to run the result

Bash

kubectl apply -f manifests.yaml       # create everything
kubectl get pods,svc                  # check the result
kubectl apply -k .                    # when you use kustomization.yaml
kubectl delete -f manifests.yaml      # remove it again
Report a problem