• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

kelseyhightower/compose2kube: Convert docker-compose service files to Kubernetes ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

kelseyhightower/compose2kube

开源软件地址(OpenSource Url):

https://github.com/kelseyhightower/compose2kube

开源编程语言(OpenSource Language):

Go 100.0%

开源软件介绍(OpenSource Introduction):

compose2kube

Convert docker-compose service files to Kubernetes objects.

Status

compose2kube is in functional beta stage and supports mapping container images, varables, ports, labels, volumes, and restart policies to Kubernetes replication controllers and services. Thanks to the docker/libcompose library, compose2kube will support the complete docker-compose specification in the near future.

Rancher support: (optionally) compose2kube also reads rancher-compose.yml in order to get the information about scale and healthchecks of the containers.

Set your GOPATH environment

For example:

export GOPATH=`pwd`/gopath

Install dependencies

go get -v ./...

Build

go build

Usage

Create a docker-compose.yml file

web:
  image: nginx
  ports:
    - "80"
    - "443"
database:
  image: postgres
  ports:
    - "5432"
cache:
  image: memcached
  ports:
    - "11211"

Test the service using the docker-compose command:

docker-compose up -d

List the running services:

docker-compose ps

Stop the services:

docker-compose stop

Remove the services:

docker-compose rm

At this point the docker-compose.yml file is ready for conversion.

docker-compose to Kubernetes

Use the compose2kube command to convert compose files to native Kubernetes objects. By default, compose2kube will search for docker-compose.yml and rancher-compose.yml in the current directory. You can change that with compose-file-path option

$ compose2kube -output-dir output
output/cache-rc.yaml
output/cache-srv.yaml
output/database-rc.yaml
output/database-srv.yaml
output/web-rc.yaml
output/web-srv.yaml
output/rancher-compose.yml

Launch the Kubernetes replication controllers

$ kubectl create -f output/
replicationcontrollers/cache
services/cache
replicationcontrollers/database
services/database
replicationcontrollers/web
services/web

List the replication controllers:

$ kubectl get rc
CONTROLLER   CONTAINER(S)   IMAGE(S)    SELECTOR           REPLICAS
cache        cache          memcached   service=cache      1
database     database       postgres    service=database   1
web          web            nginx       service=web        1

List the services:

kubectl get services
NAME       CLUSTER_IP     EXTERNAL_IP   PORT(S)          SELECTOR           AGE
cache      10.43.32.169   <none>        11211/TCP        service=cache      5m
database   10.43.32.170   <none>        5432/TCP         service=database   5m
web        10.43.32.171   <none>        80/TCP,443/TCP   service=web        5m

View the service pods:

$ kubectl get pods
NAME                             READY     STATUS    RESTARTS   AGE
cache-i3az8                      1/1       Running   0          6h
database-jq2lr                   1/1       Running   0          6h
kube-controller-172.16.238.141   4/4       Running   0          6h
web-1vj6h                        1/1       Running   0          6h

Advanced Features

Environment Variables

Environment variables may be injected into the container.

web:
  image: nginx
  ports:
    - "80"
    - "443"
  environment:
    - NGINX_HOST=example.com

Modifying the default command

The default command may be overwritten with the "command" option.

web:
  image: nginx
  ports:
    - "80"
    - "443"
  command:
    - apt update

Host Volumes

For volumes, we currently only support mounting a host volume to a container.

The host volume is by default writable. The :ro option may be appended to bind the volume as read only.

web:
  image: nginx
  ports:
    - "80"
    - "443"
  volumes:
    - /srv/nginx/uploads:/usr/share/nginx/uploads # Writable
    - /srv/nginx/html:/usr/share/nginx/html:ro    # Read Only



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap