Kompose is a conversion tool for Docker Compose to container orchestrators such as Kubernetes (or OpenShift). In this example, I’ll be using a Mac along with Minikube. I’ll be exposing a NodePort in order to view the services within a browser.
brew install kompose
INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
INFO Deploying application in "default" namespace
INFO Successfully created Service: httpd
INFO Successfully created Service: nginx
INFO Successfully created Deployment: httpd
INFO Successfully created Deployment: nginx
Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.
kubectl get deployment,svc,pods,pvc
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.extensions/httpd 1 1 1 1 18s
deployment.extensions/nginx 1 1 1 1 18s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/httpd NodePort 10.105.90.34 <none> 80:32735/TCP 18s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 47m
service/nginx NodePort 10.107.12.222 <none> 80:30180/TCP 18s
NAME READY STATUS RESTARTS AGE
pod/httpd-69c7f65b8c-xxlld 1/1 Running 0 18s
pod/nginx-5684848c75-8szsk 1/1 Running 0 18s
View service in browser
minikube service httpd
minikube service nginx
INFO Deleting application in "default" namespace
INFO Successfully deleted Service: httpd
INFO Successfully deleted Service: nginx
INFO Successfully deleted Deployment: httpd
INFO Successfully deleted Deployment: nginx
Kompose also has the ability to take existing compose files and generate the related Kubernetes Manifest files.
ll | grep yaml
-rw-r--r--@ 1 tommy staff 223B Jan 2 10:49 docker-compose.yaml
-rw-r--r--@ 1 tommy staff 564B Jan 2 10:50 httpd-deployment.yaml
-rw-r--r--@ 1 tommy staff 381B Jan 2 10:50 httpd-service.yaml
-rw-r--r--@ 1 tommy staff 564B Jan 2 10:50 nginx-deployment.yaml
-rw-r--r--@ 1 tommy staff 381B Jan 2 10:50 nginx-service.yaml
Kompose also supports different Kubernetes distributions, for example OpenShift.
kompose --provider openshift convert
By default, Kompose generates YAML files. It is also possible to generate JSON based files by specifying the -j parameter.
kompose convert -j