How to convert the following code for docker-compose to Kubernetes YAML file.
version: '3.8'
services:
mongo:
image: mongo
restart: always
ports:
- 27017:27017
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
2
Answers
You will need several components, firstly, a service, that will get the http request. Then a Deployment to create the actual pod, if you need volume so also a Persistent Volume. In my repository you can find docker compose yaml converted to k8s. Of course, you will probably need to change some data.
The kompose project is a project that provides a tool that does specifically this — converts a docker-compose file into a set of Kubernetes yaml files. It might be worth a look for you.
For simple docker-compose files like this it would work fine. But for more complicated ones, it might over-complicate things, so YMMV and all.