Skip to content

haj/kompose

 
 

Repository files navigation

Kubernetes compose (Kompose)

=============================== Build Status

kompose is a fork of libcompose which is a Go library for Docker Compose. kompose adds Kubernetes support. It takes a Docker Compose file and translates it into Kubernetes objects, it then submits those objects to a Kubernetes endpoint.

kompose is a convenience tool to go from local Docker development to managing your application with Kubernetes. We don't assume that the transformation from docker compose format to Kubernetes API objects will be perfect, but it helps tremendously to start Kubernetizing your application.

Download

Grab the latest release

For example on OSX:

$ sudo wget https://github.com/skippbox/kompose/releases/download/v0.0.3/kompose_darwin-amd64.tar.gz
$ sudo tar zxf kompose_darwin-amd64.tar.gz && \
mv kompose_darwin-amd64/kompose /usr/local/bin/kompose && \
chmod +x /usr/local/bin/kompose

Usage

You need a Docker Compose file handy. There is a sample gitlab compose file in the samples/ directory for testing. You will convert the compose file to K8s objects with kompose k8s convert.

$ cd samples/

$ ls
docker-gitlab.yml

$ kompose k8s convert -f docker-gitlab.yml -y

$ ls
docker-gitlab.yml       gitlab-rc.yaml   postgresql-deployment.yaml  postgresql-svc.yaml      redisio-rc.yaml
gitlab-deployment.yaml  gitlab-svc.yaml  postgresql-rc.yaml          redisio-deployment.yaml  redisio-svc.yaml

Next step you will submit these above objects to a kubernetes endpoint on localhost:8080 If you have a remote Kubernetes endpoint, simply run a proxy with kubectl proxy --port=8080.

$ kompose k8s up

Check that the replication controllers and services have been created.

$ kubectl get rc
NAME         DESIRED   CURRENT   AGE
gitlab       1         1         1m
postgresql   1         1         1m
redisio      1         1         1m

$ kubectl get svc
NAME         CLUSTER-IP     EXTERNAL-IP   PORT(S)               AGE
gitlab       10.0.247.129   nodes         10080/TCP,10022/TCP   1m
kubernetes   10.0.0.1       <none>        443/TCP               17h
postgresql   10.0.237.13    <none>        5432/TCP              1m
redisio      10.0.242.93    <none>        6379/TCP              1m

By default, svc generated by kompose uses Type: ClusterIP which means svc is only accessible internally. Sometimes you might be interesting to make it public from outside, simply run:

$ kubectl edit svc gitlab

Change Service.Spec.Type to NodePort and save.

$ kubectl describe svc gitlab
Name:			    gitlab
Namespace:		    default
Labels:			    service=gitlab
Selector:		    service=gitlab
Type:			    NodePort
IP:			        10.0.247.129
Port:			    10080	10080/TCP
NodePort:		    10080	31925/TCP
Endpoints:		    10.244.0.12:80
Port:			    10022	10022/TCP
NodePort:		    10022	30232/TCP
Endpoints:		    10.244.0.12:22
Session Affinity:	None
No events.

Then you can access to gitlab at: http://Node_IP:31925

kompose also allows you to list the replication controllers and services with the ps subcommand. You can delete them with the delete subcommand.

$ kompose k8s ps --rc
Name           Containers     Images                        Replicas  Selectors           
redisio        redisio        sameersbn/redis               1         service=redisio
postgresql     postgresql     sameersbn/postgresql:9.4-18   1         service=postgresql
gitlab         gitlab         sameersbn/gitlab:8.6.4        1         service: gitlab

$ kompose k8s ps --svc
Name         Cluster IP          Ports                   Selectors
gitlab       10.0.247.129        TCP(10080),TCP(10022)   service=gitlab
postgresql   10.0.237.13         TCP(5432)               service=postgresql
redisio      10.0.242.93         TCP(6379)               service=redisio


$ kompose k8s delete --rc --name gitlab
$ kompose k8s ps --rc
Name           Containers     Images                        Replicas  Selectors
redisio        redisio        sameersbn/redis               1         service=redisio
postgresql     postgresql     sameersbn/postgresql:9.4-18   1         service=postgresql

And finally you can scale a replication controller with scale.

$ kompose k8s scale --scale 3 --rc redisio
Scaling redisio to: 3
$ kompose k8s ps --rc
Name           Containers     Images                        Replicas  Selectors           
redisio        redisio        sameersbn/redis               3         service=redisio

Note that you can of course manage the services and replication controllers that have been created with kubectl. The command of kompose have been extended to match the docker-compose commands.

Alternate formats

The default kompose transformation will generate replication controllers and services and in format of json. You have alternative option to generate yaml with -y. Also, you can alternatively generate Deployment objects, DeamonSet, ReplicaSet or Helm charts.

$ kompose k8s convert -d -y
$ ls
$ tree
.
├── docker-compose.yml
├── redis-deployment.yaml
├── redis-rc.yaml
├── redis-svc.yaml
├── web-deployment.yaml
└── web-rc.yaml

The *deployment.yaml files contain the Deployments objects

$ kompose k8s convert --ds -y
$ tree .
  .
  ├── redis-daemonset.yaml
  ├── redis-rc.yaml
  ├── redis-svc.yaml
  ├── web-daemonset.yaml
  ├── web-rc.yaml
  └── web-svc.yaml

The *daemonset.yaml files contain the DaemonSet objects

$ kompose k8s convert --rs -y
$ tree .
.
├── redis-rc.yaml
├── redis-replicaset.yaml
├── redis-svc.yaml
├── web-rc.yaml
├── web-replicaset.yaml
└── web-svc.yaml

The *replicaset.yaml files contain the ReplicaSet objects

$ kompose k8s convert -c -y
$ tree docker-compose/
docker-compose/
├── Chart.yaml
├── README.md
└── manifests
    ├── redis-rc.yaml
    ├── redis-svc.yaml
    └── web-rc.yaml

The chart structure is aimed at providing a skeleton for building your Helm charts.

Building

You need either Docker and make, or go in order to build libcompose. To simplify this a Vagrantfile is provided.

Building with Vagrant

After cloning the repo, vagrant up and use make inside the machine

$ git clone https://github.com/skippbox/kompose.git
$ cd kompose
$ vagrant up
$ vagrant ssh
$ cd /vagrant
$ make binary

The binaries will be in the bundles/ directory

$ ls bundles/
kompose_darwin-386		kompose_linux-386		kompose_linux-arm		kompose_windows-amd64.exe
kompose_darwin-amd64		kompose_linux-amd64		kompose_windows-386.exe

Building with docker

You need Docker and make and then run the binary target. This will create binary for all platform in the bundles folder.

$ make binary
docker build -t "libcompose-dev:refactor-makefile" .
# […]
---> Making bundle: binary (in .)
Number of parallel builds: 4

-->      darwin/386: github.com/docker/libcompose/cli/main
-->    darwin/amd64: github.com/docker/libcompose/cli/main
-->       linux/386: github.com/docker/libcompose/cli/main
-->     linux/amd64: github.com/docker/libcompose/cli/main
-->       linux/arm: github.com/docker/libcompose/cli/main
-->     windows/386: github.com/docker/libcompose/cli/main
-->   windows/amd64: github.com/docker/libcompose/cli/main

Building with go

  • You need go v1.5
  • You need to set export GO15VENDOREXPERIMENT=1 environment variable
  • If your working copy is not in your GOPATH, you need to set it accordingly.
$ go generate
# Generate some stuff
$ go build -o libcompose ./cli/main

Contributing and Issues

kompose is a work in progress, we will see how far it takes us. We welcome any pull request to make it even better. If you find any issues, please file it.

About

Transform your Docker compose files in Kubernetes objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 93.6%
  • Shell 5.8%
  • Makefile 0.6%