[英]Kubernetes - “convert” docker-compose yaml “command” segment into k8s command and args
[英]docker-compose to K8S deployment
我已经通过 Docker 使用 docker-compose.yml 文件构建了一个应用程序,现在我正在尝试将其转换为 K8S 的部署文件。
我尝试使用kompose convert
命令,但它似乎很奇怪。
这是我的 docker-compose.yml:
version: "3"
services:
worker:
build:
dockerfile: ./worker/Dockerfile
container_name: container_worker
environment:
- PYTHONUNBUFFERED=1
volumes:
- ./api:/app/
- ./worker:/app2/
api:
build:
dockerfile: ./api/Dockerfile
container_name: container_api
volumes:
- ./api:/app/
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "8050:8050"
depends_on:
- worker
这是kompose convert
命令的输出:
[root@user-cgb4-01-01 vm-tracer]# kompose convert
WARN Volume mount on the host "/home/david/vm-tracer/api" isn't supported - ignoring path on the host
WARN Volume mount on the host "/var/run/docker.sock" isn't supported - ignoring path on the host
WARN Volume mount on the host "/home/david/vm-tracer/api" isn't supported - ignoring path on the host
WARN Volume mount on the host "/home/david/vm-tracer/worker" isn't supported - ignoring path on the host
INFO Kubernetes file "api-service.yaml" created
INFO Kubernetes file "api-deployment.yaml" created
INFO Kubernetes file "api-claim0-persistentvolumeclaim.yaml" created
INFO Kubernetes file "api-claim1-persistentvolumeclaim.yaml" created
INFO Kubernetes file "worker-deployment.yaml" created
INFO Kubernetes file "worker-claim0-persistentvolumeclaim.yaml" created
INFO Kubernetes file "worker-claim1-persistentvolumeclaim.yaml" created
它为我创建了 7 个 yaml 文件。 但我预计只有一个部署文件。 另外,我不明白我收到的这些警告。 我的音量有问题吗?
也许手动将 docker-compose 转换为 deployment.yml 会更容易?
谢谢,
我建议使用 Kompose 作为起点或灵感,而不是端到端的解决方案。 它确实有一些真正的限制,如果不了解 Kubernetes 的部署模型,就很难纠正这些限制。
在你开始之前,我会清理你docker-compose.yml
文件。 您有volumes:
将您的源代码注入容器中,可能会将应用程序代码隐藏在映像中。 此设置在 Kubernetes 中大多不起作用(集群无法返回到您的本地系统),您需要删除这些volumes:
mounts。 这样做可以消除关于不受支持的主机路径安装和 PersistentVolumeClaim 对象的 Kompose 警告。
您通常也不需要指定container_name:
或其他几个与网络相关的选项。 Kubernetes 不支持多个网络,因此如果您有任何networks:
设置它们将被忽略,但大多数实用的 Compose 文件也不需要它们。 过时的links:
和expose:
选项,如果你有它们,通常也可以安全地删除而不会产生任何后果。
version: "3.8"
services:
worker:
build:
dockerfile: ./worker/Dockerfile
environment:
- PYTHONUNBUFFERED=1
api:
build:
dockerfile: ./api/Dockerfile
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "8050:8050"
depends_on: # won't have an effect in Kubernetes,
- worker # but still good Docker Compose practice
Docker 套接字的绑定挂载是一个更大的问题。 这个套接字在 Kubernetes 中通常不存在,如果它存在,它通常是不可访问的(有一个主要的安全问题是让它可用,它允许你启动非托管容器以及 root 节点)。 如果您需要动态启动容器,则需要使用Kubernetes API来代替(查看创建一次性 作业)。 出于许多实际目的,将长时间运行的工作容器连接到像 RabbitMQ 这样的队列系统是一种更好的方法。 Kompose 无法解决这个架构问题,但是,您将不得不修改您的代码。
完成所有这些后,我希望 Kompose 创建四个文件,每个文件都有一个 Kubernetes YAML 清单:两个Deployments和两个匹配的Services 。 您的每个 Docker Compose services:
都将被转换为单独的 Kubernetes 部署,并且您需要配对的 Kubernetes 服务才能连接到它(甚至从集群内部)。 有许多相关的对象通常很有用(ServiceAccounts、PodDisruptionBudgets、HorizontalPodAutoscaler),典型的 Kubernetes 实践是将每个对象放在自己的文件中。
我想这很好:
通常情况下应该是这样。
但是,如果您在部署这些文件时感到困惑; 尝试 -
kubectl apply -f mymanifests/*.yaml
- 这将一次性部署。
或者,如果您只想要一个 fine ,您可以将所有这些文件与---------
一个接一个地连接起来; 它可用于分隔多个清单,但仍将它们放在一个文件中。 就像是 -
apiVersion.... deploymentfile....
-------------
apiVersion.... servicefile...... and so on...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.