Kubernetes + Compose = Kompose

docker composeで使ってたymlをkubernetes向けにコンバートしてくれるツールを使ってみたのでメモ

インストール

落として権限つけるだけで使えます

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// ダウンロード
$ sudo curl -L https://github.com/kubernetes/kompose/releases/download/v1.9.0/kompose-linux-amd64 -o /usr/local/bin/kompose
$ sudo chmod +x /usr/local/bin/kompose
$ kompose
Kompose is a tool to help users who are familiar with docker-compose move to Kubernetes.

Usage:
kompose [command]

Available Commands:
completion Output shell completion code
convert Convert a Docker Compose file
down Delete instantiated services/deployments from kubernetes
help Help about any command
up Deploy your Dockerized application to a container orchestrator.
version Print the version of Kompose

Flags:
--error-on-warning Treat any warning as an error
-f, --file stringArray Specify an alternative compose file
-h, --help help for kompose
--provider string Specify a provider. Kubernetes or OpenShift. (default "kubernetes")
--suppress-warnings Suppress all warnings
-v, --verbose verbose output

Use "kompose [command] --help" for more information about a command.

使ってみる

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

// サンプルダウンロード
$ wget https://raw.githubusercontent.com/kubernetes/kompose/master/examples/docker-compose-v3.yaml

// コンバート
$ kompose -f ./docker-compose-v3.yaml 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

$ ll
合計 28
-rw-r--r-- 1 9zilla 9zilla 421 3月 1 21:48 docker-compose-v3.yaml
-rw-r--r-- 1 9zilla 9zilla 710 3月 1 21:49 frontend-deployment.yaml
-rw-r--r-- 1 9zilla 9zilla 432 3月 1 21:49 frontend-service.yaml
-rw-r--r-- 1 9zilla 9zilla 608 3月 1 21:49 redis-master-deployment.yaml
-rw-r--r-- 1 9zilla 9zilla 390 3月 1 21:49 redis-master-service.yaml
-rw-r--r-- 1 9zilla 9zilla 687 3月 1 21:49 redis-slave-deployment.yaml
-rw-r--r-- 1 9zilla 9zilla 387 3月 1 21:49 redis-slave-service.yaml

// 中身はこんな感じ
$ head frontend-service.yaml
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose -f ./docker-compose-v3.yaml convert
kompose.service.type: LoadBalancer
kompose.version: 1.9.0 (093c756)
creationTimestamp: null
labels:
io.kompose.service: frontend