当前位置: 首页 > 文档资料 > Kubernetes 指南 >

6. 服务治理 - Kompose

优质
小牛编辑
121浏览
2023-12-01

Kompose是一个将docker-compose配置转换成Kubernetes manifests的工具,官方网站为http://kompose.io/

Kompose安装

  1. # Linux
  2. $ curl -L https://github.com/kubernetes-incubator/kompose/releases/download/v0.5.0/kompose-linux-amd64 -o kompose
  3. # macOS
  4. $ curl -L https://github.com/kubernetes-incubator/kompose/releases/download/v0.5.0/kompose-darwin-amd64 -o kompose
  5. # Windows
  6. $ curl -L https://github.com/kubernetes-incubator/kompose/releases/download/v0.5.0/kompose-windows-amd64.exe -o kompose.exe
  7. # 放到PATH中
  8. $ chmod +x kompose
  9. $ sudo mv ./kompose /usr/local/bin/kompose

Kompose使用

docker-compose.yaml

  1. version: "2"
  2. services:
  3. redis-master:
  4. image: gcr.io/google_containers/redis:e2e
  5. ports:
  6. - "6379"
  7. redis-slave:
  8. image: gcr.io/google_samples/gb-redisslave:v1
  9. ports:
  10. - "6379"
  11. environment:
  12. - GET_HOSTS_FROM=dns
  13. frontend:
  14. image: gcr.io/google-samples/gb-frontend:v4
  15. ports:
  16. - "80:80"
  17. environment:
  18. - GET_HOSTS_FROM=dns
  19. labels:
  20. kompose.service.type: LoadBalancer

kompose up

  1. $ kompose up
  2. We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application.
  3. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
  4. INFO Successfully created Service: redis
  5. INFO Successfully created Service: web
  6. INFO Successfully created Deployment: redis
  7. INFO Successfully created Deployment: web
  8. Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.

kompose convert

  1. $ kompose convert
  2. INFO file "frontend-service.yaml" created
  3. INFO file "redis-master-service.yaml" created
  4. INFO file "redis-slave-service.yaml" created
  5. INFO file "frontend-deployment.yaml" created
  6. INFO file "redis-master-deployment.yaml" created
  7. INFO file "redis-slave-deployment.yaml" created