Sunday, August 30, 2026

Convert Docker Compose Files to Kubernetes Manifests with Kompose

Docker Compose make it easy to spin up local development environment with all of application dependencies using a single Compose file. However, when we want to run the same application on Kubernetes, we normally need Kubernetes configuration files such as, deployment, service, etc. In this blog we’ll explore how Kompose works, how to use it to generate Kubernetes configurations from an existing Compose file, and what you should review or modify before deploying the generated manifests to a Kubernetes cluster.


Pre-requisites:

  • Docker installed
  • Kind installed
  • kubectl installed
  • An existing Docker Compose file for the application


Let's get started by installing Kompose. Open PowerShell and run the following command to install Kompose.

winget install Kubernetes.kompose



Now, we have the tool required for the conversion, let's create a local Kubernetes cluster before converting the Compose file. Run the following command.

kind create cluster --name=kompose-learn



We are now ready to perform the conversion. Run the following command to generate Kubernetes manifest files from the existing Docker Compose file

kompose convert -f docker-compose.yml



Before applying the Kubernetes manifest files, we need to update the generated Deployment file with the correct image name. By default, the generated manifest may contain an incorrect name, so we need to update it before applying the manifest to the cluster.



Let's run the following command to apply the generated Kubernetes manifests to the cluster.
kubectl apply -f .



After that, we should be able to see the Pods and Services running in the Kubernetes cluster. Now, let's set up port forwarding to access the application deployed on Kubernetes. 


kubectl port-forward service/api 8081:8080





No comments:

Post a Comment