【问题标题】:Converting docker-compose to a helm chart?将 docker-compose 转换为掌舵图?
【发布时间】:2020-06-12 04:32:26
【问题描述】:

我有一个包含 2 个图像的 docker-compose 文件,用于我正在使用的安全工具。我的挑战是将其转换为由 deployment.yaml 和 service.yaml 组成的掌舵图。 docker-compose 看起来像这样 -

  version: '3'

  services:

  nginx:
    ports:
      - "80:80"
      - "443:443"
    environment:
      - NG_SERVER_NAME=192.168.1.228
    links:
      - tomcat8
    image: continuumsecurity/iriusrisk-prod:nginx-prod-ssl
    container_name: iriusrisk-nginx
    volumes:
      - "./cert.pem:/etc/nginx/ssl/star_iriusrisk_com.crt"
      - "./key.pem:/etc/nginx/ssl/star_iriusrisk_com.key"

  tomcat8:
    environment:
      - IRIUS_DB_URL=jdbc\:postgresql\://192.168.1.228\:5432/iriusprod?user\=iriusprod&password\=alongandcomplexpassword2523
      - IRIUS_EDITION=saas
      - IRIUS_EXT_URL=http\://192.168.1.228
      - grails_env=production
    image: continuumsecurity/iriusrisk-prod:tomcat8-2
    container_name: iriusrisk-tomcat8

还有一个 postgres 服务器正在运行,我可以将其转换为 helm 图表并将其公开到端口 5432 上的我的 ip (192.168.1.228)。但是对于相互链接的 iriusrisk 和 tomcat 图像,我我无法弄清楚。这一直是我对两者的部署文件的解决方案。

部署-tomcat.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat
  labels:
    app: {{ .Values.tomcat.app.name }}
spec:
  replicas: {{ .Values.tomcat.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.tomcat.app.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.tomcat.app.name }}
    spec:
      {{- if .Values.tomcat.imagePullSecretsName }}
      imagePullSecrets:
      - name: {{ .Values.tomcat.imagePullSecretsName }}
      {{- end}}
      restartPolicy: Always
      serviceAccountName: {{ .Values.tomcat.serviceAccountName }}

      containers:
      - name: {{ .Values.tomcat.app.name }}
        image: "{{ .Values.tomcat.ImageName }}:{{ .Values.tomcat.ImageTag }}"
        container_name: iriusrisk-tomcat8
        imagePullPolicy: {{ .Values.tomcat.ImagePullPolicy }}
        ports:
        - containerPort: {{ .Values.tomcat.port }}
        env:
          - name: IRIUS_DB_URL
            value: jdbc\:postgresql\://192.168.1.228\:5432/iriusprod?user\=iriusprod&password\=alongandcomplexpassword2523
          - name: IRIUS_EDITION
            value: saas
          - name: IRIUS_EXT_URL
            value: http\://192.168.1.228
          - name: grails_env
            value: production

部署-iriusrisk.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: iriusrisk
  labels:
    app: {{ .Values.iriusrisk.app.name }}
spec:
  replicas: {{ .Values.iriusrisk.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.iriusrisk.app.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.iriusrisk.app.name }}
    spec:
      {{- if .Values.iriusrisk.imagePullSecretsName }}
      imagePullSecrets:
      - name: {{ .Values.iriusrisk.imagePullSecretsName }}
      {{- end}}
      restartPolicy: Always
      serviceAccountName: {{ .Values.iriusrisk.serviceAccountName }}

      containers:
      - name: {{ .Values.iriusrisk.app.name }}
        image: "{{ .Values.iriusrisk.ImageName }}:{{ .Values.iriusrisk.ImageTag }}"
        container_name: iriusrisk-nginx
        imagePullPolicy: {{ .Values.iriusrisk.ImagePullPolicy }}
        ports:
        - containerPort: {{ .Values.iriusrisk.port }}
        env:
          - name: NG_SERVER_NAME
            value: "192.168.1.228"
        volumes: 
          - "./cert.pem:/etc/nginx/ssl/star_iriusrisk_com.crt"
          - "./key.pem:/etc/nginx/ssl/star_iriusrisk_com.key"

我应该如何解决这个问题?我看过彼此“链接”豆荚,但我尝试过的解决方案都没有奏效。我对此有点陌生,因此我仍然对如何公开 pod 并相互连接感到有些困惑。

【问题讨论】:

  • "Link" 即使在当前的 Docker 中也没有任何意义。在 Kubernetes 中,您几乎总是需要 Service 来将连接路由到 pod,甚至在 pod 之间也是如此。我希望这个设置需要两个部署、两个服务和一个秘密。
  • 谢谢。我将尝试为部署和服务计算我的 yaml 文件。

标签: docker docker-compose kubernetes-helm kubernetes-pod helmfile


【解决方案1】:

我认为没有必要从 helm chart 转换为 docker-compose。您可以使用 Minikube 在本地运行所需的任何内容。否则,另一种选择是在本地运行容器并进行逆向工程。即生成 docker compose 文件。这是一个指向 GitHub 的链接,它会为您执行此操作https://github.com/Red5d/docker-autocompose

祝你好运

【讨论】:

    【解决方案2】:

    kompose 工具现在包括从 docker-compose.yml 文件转换为 Helm 图表的功能:

    kompose convert -c

    查看 kompose Alternative Conversions 文档。

    【讨论】:

    • 指向替代转化的链接指向死胡同。
    • @JuanJimenez 这很奇怪。我刚才检查时链接是有效的。
    • 我想知道它是否受到了 Fastly CDN 中断的打击。
    【解决方案3】:

    根据我目前的知识,没有开发或发布将 helm-chart 转换为 docker-compose 文件的工具。但是从docker-compose 到kubernetes 资源清单的转换可以使用kompose (https://kompose.io) 之类的工具来完成。

    【讨论】:

    • 谢谢。我会看看这个工具。
    • 我们有什么东西可以将 helm 图表转换为 docker-compose 文件吗?我们需要不支持 Kubernetes 的开发环境,但我们需要重用我们的 helm 图表
    • @Tiny 在这种情况下,它需要编写自定义的。
    • @ShudiptaSharma - 任何可以使用的工具?
    • kompose 现在包含一个helm chart conversion 选项kompose convert -c
    猜你喜欢
    • 2019-03-15
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多