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:
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:
Your .env file would have the values:
We can use a docker-compose command to fill in the variables:
Now that we have actual values in our docker-compose-out.yml file we can use kompose to convert that file:
That will create our deployment, service, and persistent volume claim files. To spin up our kubernetes cluster we can run the command:
Read more about it here