Kompose 将 Docker Compose 文件转换为 Kubernetes 资源

作者: Ju4t

Kompose 是什么?它是一个转换工具,可将 compose (即 Docker Compose)所组装的所有内容转换成容器编排器(Kubernetes 或 OpenShift)可识别的形式。

Kompose 通过 GitHub 发布,发布周期为三星期。 你可以在 GitHub 发布页面上看到所有当前版本。

安装 Kompose

# macOS
curl -L https://github.com/kubernetes/kompose/releases/download/v1.26.0/kompose-darwin-amd64 -o kompose

chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose

使用 Kompose

  1. 进入 docker-compose.yml 文件所在的目录。如果没有,请使用下面这个进行测试。
  2. 要将 docker-compose.yml 转换为 kubectl 可用的文件,请运行 kompose convert 命令进行转换,然后运行 kubectl apply -f 进行创建。
  3. kubectl apply -f frontend-service.yaml,redis-master-service.yaml,redis-slave-service.yaml,frontend-deployment.yaml,redis-master-deployment.yaml,redis-slave-deployment.yaml
kompose convert
WARN Unsupported depends_on key - ignoring        
WARN Volume mount on the host "./.docker/redis" isn't supported - ignoring path on the host 
INFO Kubernetes file "ace-admin-service.yaml" created 
INFO Kubernetes file "ace-auth-service.yaml" created 
INFO Kubernetes file "ace-gate-service.yaml" created 
INFO Kubernetes file "eureka-service.yaml" created 
INFO Kubernetes file "redis-service.yaml" created 
INFO Kubernetes file "ace-admin-deployment.yaml" created 
INFO Kubernetes file "ace-auth-deployment.yaml" created 
INFO Kubernetes file "ace-gate-deployment.yaml" created 
INFO Kubernetes file "eureka-deployment.yaml" created 
INFO Kubernetes file "redis-deployment.yaml" created 
INFO Kubernetes file "redis-claim0-persistentvolumeclaim.yaml" created

https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/translate-compose-kubernetes/