Journey from Docker Compose to Kubernetes

Milind Chavan
3 min readFeb 20, 2021

--

If you worked with Docker Compose in the past, then you know it’s a great tool. It provides all kinds of functionality, from building images to running containers, and logging into container for debugging or checking logs and many more.

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. — Docker Documentation.

Mapping Docker Compose to Kubernetes

To map the docker compose to Kubernetes services and deployment, a process for each resource from docker must be translated. Let’s visualise this:

An example of docker compose in perspective of Kubernetes

Now we can do this translation manually one by one by remembering all syntax and parameters, Or choose following 3 ways to create K8s services:

1. Kubernetes using Docker Stack

Docker stack commands out of the box are used to manage this swarm mode. Clustering, however, with the check of a check box from the Docker Desktop we can switch it. So instead of creating a swarm cluster, it can actually put all of our containers into pods within kubernetes.

To enable Docker Stacks Command to Kubernetes

Normally you have to do a swarm initializer phase, run a command and get your Docker swarm configured and enabled. But by checking this check box, you can override that default behavior and make it so it runs these up in kubernetes.

2. Kubernetes using Kompose

Kompose is a tool to help users familiar with docker-compose move to Kubernetes. It takes a Docker Compose file and translates it into Kubernetes resources.

To install kompose, follow instruction on : https://kompose.io/installation/

To convert the docker files to kubernetes yaml, use following command in de docker-compose directory with options:

$ kompose convert --file docker-compose.yaml --out ./k8s

This command will convert docker services to kubernetes services and deployments in k8s folder.

3. Kubernetes using Skaffold

Skaffold is a command line tool that facilitates continuous development for Kubernetes-native applications. Skaffold handles the workflow for building, pushing, and deploying your application, and provides building blocks for creating CI/CD pipelines. This enables you to focus on iterating on your application locally while Skaffold continuously deploys to your local or remote Kubernetes cluster.

To install kompose, follow instruction on : https://skaffold.dev/docs/install/

Generating a skaffold.yaml : skaffold init can be used to generate the initial configuration to deploy a project to kubernetes.

$ skaffold init --compose-file docker-compose.yml

Once skaffold.yml is generated, skaffold dev can be to watches code for changes and build and deploys it automatically to kubernetes cluster.

--

--

Milind Chavan
Milind Chavan

Written by Milind Chavan

An Azurer, Web developer, Technologist, Writer, Poet, Runner. Opinions are my own.

No responses yet