Converting Docker Compose To Kubernetes Files

Kubernetes is a container orchestration system for automating deployment scaling and management. At some point you might outgrow using Docker and want to use Kubernetes to manage your containers. There are some great tools to make that transition easier. Note in this example we’re supporting local development as we’re going to use local volumes. Persistent Volumes in kubernetes are handled differently than you would locally.

Using Kompose, you can take a docker-compose file and easily convert that into Kubernetes service, deploy, and persistent volume claim files fairly easily. First you’ll need to install kompose:

# Linux
curl -L -o kompose

# macOS
curl -L -o kompose

chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose

If you have environment variables and use those in an .env file to fill the docker compose file, those variables need to be filled in in order for the kubernetes deployment file to receive those. So, for example if your file structure looks like this:


In your docker-compose file you, for example have variables for environment variables:

version: "3.7"

    image: ${REPO}/node_app:${BE_TAG}
      - ${NODE_PORT}:3000
    restart: on-failure:3

Your .env file would have the values:


We can use a docker-compose command to fill in the variables:

docker-compose -f app.yml config > docker-compose-out.yml

Now that we have actual values in our docker-compose-out.yml file we can use kompose to convert that file:

kompose convert -f docker-compose-out.yml

That will create our deployment, service, and persistent volume claim files. To spin up our kubernetes cluster we can run the command:

kubectl apply -f .

Read more about it here