kompose is basically a deployment accelerator tool to help users who are familiar with
docker-compose format and move to Kubernetes.In this post, we are going to take a sample Docker compose file and convert it using kompose utility.
What is Docker Compose ?
With Compose tool, you can define and start running multi-container Docker applications. There would be a YAML file to configure your application’s services. Then, with a single command, you can create and start all the services from your configuration.
Here are the steps involved :
Dockerfilefor your app’s environment.
docker-compose.ymlfor the services that make up your app services.
docker-compose upand Compose starts and runs your entire app.
docker-compose.yml looks like this:
Key Features of Docker Compose
- When you define the Compose file, you can use project name to isolate environments from each other. This could be useful in cases like creating multiple copies of a single environment or segregate the builds by a unique build number.
- Compose caches the configuration used to create a container. When you restart a service that has not changed, Compose re-uses the existing containers. It means that you can make changes to your environment very quickly.
- Compose preserves all volumes used by your services. When
docker-compose upruns, if it finds any containers from previous runs, it copies the volumes from the old container to the new container. This process ensures that any data you’ve created in volumes isn’t lost.
- Compose supports variables in the Compose file. You can use these variables to customize your composition for different environments or different users.
In the next sections, we can look at how to Install Kompose and use existing Compose files and generate the related Kubernetes Manifest files.
Install Kompose by downloading the binary from the latest GitHub release page.
If you’re looking for other platforms, check out here.
Convert Docker Compose file to Kubernetes using Kompose
There are 2 ways you can do the conversion of the Docker Compose format to Kubernetes resources manifest.
kompose convert in the same directory where you have
docker-compose.yaml file, for this example, we are going to use below sample compose file.
#2. Alternatively, you can use command
kompose up to bring up the Images to be deployed using a single command.
Kompose command, you can use
Kubectl command to see the deployments.
By default, Kompose generates YAML files. It’s also possible to generate JSON based files by specifying the
Kompose currently supports 2 providers:
Kubernetes. You can choose a targeted provider using the global option
--provider. If no provider is specified, Kubernetes is set by default.
Congrats! today we have learned how to use Kompose utility to convert Docker compose file to Kubernetes artifacts.
Like this post? Don’t forget to share it!
Useful Resources :
- Kubectl cheat sheet
- Conversion Matrix for values to Kubernetes / OpenShift artifacts.
- Implementing Policies in Kubernetes
- 10 BEST Kubernetes monitoring tools
- Helm 3.0.0 is out, here is what has changed!
- Take a free course on Building Scalable Java Microservices with Spring Boot and Spring Cloud
- Kubernetes tutorial – Create simple cluster & Deploy app
- Kubernetes tutorial – Scale & perform updates to your app
- Kubernetes tutorial – Create deployments using YAML file
- If you’re looking for Kubernetes examples, here it is GitHub