Translating and Deploying a docker-compose project to Kubernetes using Kompose

I’ve chosen a LAMP stack-based demo app just because it’s a multi-tiered application that demonstrates well the power of docker-compose as a container orchestration tool. You can apply this to any docker-compose project.

The idea behind this topic is to translate docker-compose.yml file to a single kubemanifests.yaml resource file using Kompose, apply that YAML file to go to Kubernetes by creating pods and services up and running in less than a minute.

To create a local kubernetes cluster, I’ll be using Minikube.

For more about how to install Kubectl and Minikube on a local machine please visit :

Assuming that you’ve already installed kubectl and minikube.

Take a look at the project (a simple LAMP stack application with index.php connected to mySQL).

Run docker-compose up to pull images and build containers (the images will be used to build pods (containers) also if you keep the same image names on the yaml file).

Start minikube using the command : minikube start

Create another yml file called docker-compose.proc.yml (here prod doesn’t mean production :)), then copy the same content, then in docker-compose.proc.yml change the version to ‘2’ because kompose will probably fail (probably a bug) if you use 3.7.

If you are on Google Cloud

Create a Kubernetes cluster using Google Cloud Shell or the UI.

Once the cluster is created, navigate to Kubernetes clusters and hit connect to it via Cloud Shell (copy the command line and paste it into the Cloud Shell Terminal)

Convert docker-compose.yml to a single yaml manifest in your local machine

kompose convert -f -o kubemanifests.yaml

Apply the yaml manifest to create pods and services

 kubectl apply -f kubemanifests.yaml


A part of the generated manifest will look like this:

apiVersion: v1
- apiVersion: v1
  kind: Service
      kompose.cmd: kompose convert -f -o kubemanifests.yaml
      kompose.version: 1.21.0 (992df58d8)
    creationTimestamp: null
      io.kompose.service: apache
    name: apache
    type: LoadBalancer
    - name: "80"
      port: 80
      targetPort: 80
    - name: "443"
      port: 443
      targetPort: 443
      io.kompose.service: apache
    loadBalancer: {}

Get all running pods

kubectl get po

Run the command minikube dashboard to get more information about your local k8s cluster, its configuration and its components.

Next we’ll see how to expose this application to localhost and different options to deploy on Google Cloud Kubernetes Engine GKE.

Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.

Open chat
Powered by