Kompose A tool to solve kubernetes docker deployments
Previous Blog regarding Docker and Kubernetes : Here
Have you ever faced the problem on deploying a custom docker image from your local docker to Kubernetes?
Actually, there are 2 ways that can solve this problem
1. Pushing your Docker Image to any Image repository
2. Somehow tell your kubernetes (In my case minikube) to use local docker images ( Because by default minikube does not search or use pre-pulled images for deploying)
the first way comes handy for most cases because it is easy.
But for development sometimes the scenario can occur that exposing the image to any public repository may be risky.
So in that case the first method becomes invalid .
The second method comes in place which is :
We have to somehow point a local docker build be automatically done in minikube space:
Step : 1
$ eval $(minikube docker-env)window 1
$ minikube ssh
$ docker imageswindow 2
$ docker imagescheck the o/p of window 1 and window 2 are same or not if yes then the work is done:
Now any docker build will automatically create docker image under minikube spaceNow the Problem is
Now the problem with this method is though it is handy but, it is not kind of industry practice plus in real Kubernetes cluster, it may break the whole architecture.
What is the solution?
here comes the use of Kompose i.e Docker Compose + Kubernetes = Kompose.
What’s Kompose?
Kompose is a conversion tool for Docker Compose to container orchestrators such as Kubernetes (or OpenShift).
Why do developers love it?
- Simplify your development process with Docker Compose and then deploy your containers to a production cluster
- Convert your
docker-compose.yaml
with one simple commandkompose convert
- Immediately bring up your cluster with
kompose up
- Bring it back down with
kompose down
Visit Their own website
Hands-on Kompose
Create a directory in your filesystem and name it kompose (for ease of identification)
$ cd kompose
For Linux :
Download Kompose:
$curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-linux-amd64 -o kompose
After downloading
$chmod +x kompose
$sudo mv ./kompose /usr/local/bin/kompose
Now you are good to go.
Start minikube
$ minikube start
Starting local Kubernetes v1.10.0 cluster…
Starting VM…
Getting VM IP address…
Moving files into cluster…
Setting up certs…
Connecting to cluster…
Setting up kubeconfig…
Starting cluster components…
Kubectl is now configured to use the cluster.
Loading cached images from config file.
here I am working with a demo docker-compose.yaml
$ wget https://raw.githubusercontent.com/kubernetes/kompose/master/examples/docker-compose.yaml
Contents :
now converting this Kompose file we can get all required deployment and service yaml(s)from this.
$ kompose convert
INFO Kubernetes file "frontend-service.yaml" created
INFO Kubernetes file "redis-master-service.yaml" created
INFO Kubernetes file "redis-slave-service.yaml" created
INFO Kubernetes file "frontend-deployment.yaml" created
INFO Kubernetes file "redis-master-deployment.yaml" created
INFO Kubernetes file "redis-slave-deployment.yaml" created
now do a ls to see all the yaml(s) are created or not.
$ ls -l
docker-compose.yaml
frontend-deployment.yaml
frontend-service.yaml
redis-master-deployment.yaml
redis-master-service.yaml
redis-slave-deployment.yaml
redis-slave-service.yaml
Now to create the deployments and services in kubernetes we can Kompose up
$ kompose up
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 Successfully created Service: redis
INFO Successfully created Service: web
INFO Successfully created Deployment: redis
INFO Successfully created Deployment: web
Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.
Now check whether your deployments are ready or not :
run :
$ kubectl get deployment,svc,pods,pvc
The output should contain the following images:
Deployments:
redis-master, redis-slave & frontend
Services :
redis-master, redis-slave & frontend
and redis-master and redis slave pods
check minikube dashboard
$ minikube dashboard
After the deployments and image pull is complete check for the url to view the output
$ minikube service frontend — url
http://192.168.99.100:31476
Visit the site and check whether it is working or not :
Now we can easily view how this tool Kompose makes our life easy .
For The full Blog regarding Kubernetes and Docker please visit
Visit my medium profile for more such blogs:
Big Data Developer @ ThirdEyeData