Editor’s note: Today’s post is by Sebastien Goasguen, Founder of Skippbox, showing a new tool to move from ‘docker-compose’ to Kubernetes.At Skippbox, we developed kompose a tool to automatically transform your Docker Compose application into Kubernetes manifests. Allowing you to start a Compose application on a Kubernetes cluster with a single kompose up command. We’re extremely happy to have donated kompose to the Kubernetes Incubator. So here’s a quick introduction about it and some motivating factors that got us to develop it.Docker is terrific for developers. It allows everyone to get started quickly with an application that has been packaged in a Docker image and is available on a Docker registry. To build a multi-container application, Docker has developed Docker-compose (aka Compose). Compose takes in a yaml based manifest of your multi-container application and starts all the required containers with a single command docker-compose up. However Compose only works locally or with a Docker Swarm cluster.But what if you wanted to use something else than Swarm? Like Kubernetes of course.The Compose format is not a standard for defining distributed applications. Hence you are left re-writing your application manifests in your container orchestrator of choice.We see kompose as a terrific way to expose Kubernetes principles to Docker users as well as to easily migrate from Docker Swarm to Kubernetes to operate your applications in production.Over the summer, Kompose has found a new gear with help from Tomas Kral and Suraj Deshmukh from Red Hat, and Janet Kuo from Google. Together with our own lead kompose developer Nguyen An-Tu they are making kompose even more exciting. We proposed Kompose to the Kubernetes Incubator within the SIG-apps and we received approval from the general Kubernetes community; you can now find kompose in the Kubernetes Incubator.Kompose now supports Docker-compose v2 format, persistent volume claims have been added recently, as well as multiple container per pods. It can also be used to target Openshift deployments, by specifying a different provider than the default Kubernetes. Kompose is also now available in Fedora packages and we look forward to see it in CentOS distributions in the coming weeks.kompose is a single Golang binary that you build or install from the release on GitHub. Let’s skip the build instructions and dive straight into an example.Let’s take it for a spin!Guestbook application with DockerThe Guestbook application has become the canonical example for Kubernetes. In Docker-compose format, the guestbook can be started with this minimal file:version: “2”services: redis-master: image: gcr.io/google_containers/redis:e2e ports: – “6379” redis-slave: image: gcr.io/google_samples/gb-redisslave:v1 ports: – “6379” environment: – GET_HOSTS_FROM=dns frontend: image: gcr.io/google-samples/gb-frontend:v4 ports: – “80:80″ environment: – GET_HOSTS_FROM=dnsIt consists of three services. A redis-master node, a set of redis-slave that can be scaled and find the redis-master via its DNS name. And a PHP frontend that exposes itself on port 80. The resulting application allows you to leave short messages which are stored in the redis cluster.To get it started with docker-compose on a vanilla Docker host do:$ docker-compose -f docker-guestbook.yml up -dCreating network “examples_default” with the default driverCreating examples_redis-slave_1Creating examples_frontend_1Creating examples_redis-master_1So far so good, this is plain Docker usage. Now let’s see how to get this on Kubernetes without having to re-write anything.Guestbook with ‘kompose’Kompose currently has three main commands up, down and convert. Here for simplicity we will show a single usage to bring up the Guestbook application.Similarly to docker-compose, we can use the kompose up command pointing to the Docker-compose file representing the Guestbook application. Like so:$ kompose -f ./examples/docker-guestbook.yml upWe are going to create Kubernetes deployment and service for your dockerized application.If you need more kind of controllers, use ‘kompose convert’ and ‘kubectl create -f’ instead.INFO[0000] Successfully created service: redis-masterINFO[0000] Successfully created service: redis-slaveINFO[0000] Successfully created service: frontendINFO[0000] Successfully created deployment: redis-masterINFO[0000] Successfully created deployment: redis-slaveINFO[0000] Successfully created deployment: frontendApplication has been deployed to Kubernetes. You can run ‘kubectl get deployment,svc’ for details.kompose automatically converted the Docker-compose file into Kubernetes objects. By default, it created one deployment and one service per compose services. In addition it automatically detected your current Kubernetes endpoint and created the resources onto it. A set of flags can be used to generate Replication Controllers, Replica Sets or Daemon Sets instead of Deployments.And that’s it! Nothing else to do, the conversion happened automatically.Now, if you already now Kubernetes a bit, you’re familiar with the client kubectl and you can check what was created on your cluster.$ kubectl get pods,svc,deploymentsNAME READY STATUS RESTARTS AGEfrontend-3780173733-0ayyx 1/1 Running 0 1mredis-master-3028862641-8miqn 1/1 Running 0 1mredis-slave-3788432149-t3ejp 1/1 Running 0 1mNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEfrontend 10.0.0.34 <none> 80/TCP 1mredis-master 10.0.0.219 <none> 6379/TCP 1mredis-slave 10.0.0.84 <none> 6379/TCP 1mNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEfrontend 1 1 1 1 1mredis-master 1 1 1 1 1mredis-slave 1 1 1 1 1mIndeed you see the three services, the three deployments and the resulting three pods. To access the application quickly, access the _frontend_ service locally and enjoy the Guestbook application, but this time started from a Docker-compose file.Hopefully this gave you a quick tour of kompose and got you excited. They are more exciting features, like creating different type of resources, creating Helm charts and even using the experimental Docker bundle format as input. Check Lachlan Evenson’s blog on using a Docker bundle with Kubernetes. For an overall demo, see our talk from KubeConHead over to the Kubernetes Incubator and check out kompose, it will help you move easily from your Docker compose applications to Kubernetes clusters in production.Download KubernetesGet involved with the Kubernetes project on GitHub Post questions (or answer questions) on Stack Overflow Connect with the community on SlackFollow us on Twitter @Kubernetesio for latest updates
Quelle: kubernetes
Published by