kubernetes 多个部署使用一个代码库但不同的配置(环境变量)

kubernetess multiple deployments using one code base but different configuration (environement variables)

我有一个项目,我们正在使用来自 kafka 的数据并发布到 mongo。实际上代码库只做一个任务,可能是mongo到kafka的迁移,kafka到mongo的迁移或者别的什么。

我们必须从不同的 kafka 主题中消费并发布到不同的 mongo 集合。现在这些是并行的工作流。

当前的设计是拥有一个代码库,可以使用任何主题并发布到任何 mongo 集合,该集合可使用环境变量进行配置。所以我们创建了一个 kubernetes Pod,里面有多个容器。每个容器都有不同的环境变量。

我的问题:

  1. 在一个 pod 中使用多个容器是否明智。容易区分,但由于它们紧密耦合,我猜测失败的可能性很高,实际上微服务设计不正确。
  2. 我应该为每个管道创建多个部署吗?将很难维护,因为每个都有不同的部署配置。
  3. 有没有更好的方法来解决这个问题?

第 1 步示例:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: {}
  name: test-raw-mongodb-sink-apps
  namespace: test-apps
spec:
  selector:
    matchLabels:
      app: test-raw-mongodb-sink-apps
  template:
    metadata:
      labels:
        app: test-raw-mongodb-sink-apps
    spec:
      containers:
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-alchemy
        - name: INPUT_TOPIC
          value: test.raw.ptv.alchemy
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8081"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/dpl/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-alchemy
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-bloomberg
        - name: INPUT_TOPIC
          value: test.raw.pretrade.bloomberg
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8082"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-bloomberg
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-calypso
        - name: INPUT_TOPIC
          value: test.raw.ptv.calypso
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8083"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-calypso
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-dtres
        - name: INPUT_TOPIC
          value: test.raw.ptv.dtres
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8084"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-dtres
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-feds
        - name: INPUT_TOPIC
          value: test.raw.ptv.feds
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8085"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-feds
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-hoops
        - name: INPUT_TOPIC
          value: test.raw.ptv.hoops
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8086"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-hoops
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxcore
        - name: INPUT_TOPIC
          value: test.raw.ptv.murex_core
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8087"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxcore
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxeqd
        - name: INPUT_TOPIC
          value: test.raw.ptv.murex_eqd_sa
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8088"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxeqd
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxgts
        - name: INPUT_TOPIC
          value: test.raw.ptv.murex_gts_sa
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8089"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxgts
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxmr
        - name: INPUT_TOPIC
          value: test.raw.ptv.murex_mr
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8090"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxmr
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxgtscf
        - name: INPUT_TOPIC
          value: test.raw.cashflow.murex_gts_sa
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8091"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxgtscf
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxcoll
        - name: INPUT_TOPIC
          value: test.raw.collateral.mxcoll
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8092"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxcoll
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-mxcoll-link
        - name: INPUT_TOPIC
          value: test.raw.collateral.mxcoll_link
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8093"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-mxcoll-link
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-ost
        - name: INPUT_TOPIC
          value: test.raw.ptv.ost
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8094"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-ost
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      - env:
        - name: EVENTS_TOPIC
          value: test.ops.proc-events
        - name: GROUP_ID
          value: test-mongodb-sink-posmon
        - name: INPUT_TOPIC
          value: test.raw.ptp.posmon
        - name: MONGODB_AUTH_DB
          value: admin
        - name: MONGODB_HOST0
          value: test-mongodb-0.test-mongodb-headless.test-infra
        - name: MONGODB_HOST1
          value: test-mongodb-1.test-mongodb-headless.test-infra
        - name: MONGODB_PASSWORD
          value: test123
        - name: MONGODB_PORT
          value: "27017"
        - name: MONGODB_USERNAME
          value: root
        - name: SERVER_PORT
          value: "8095"
        - name: KAFKA_BROKERS
          value: kafka-cluster-kafka-bootstrap.kafka:9093
        - name: TRUSTSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: ca.password
              name: kafka-ca-cert
        - name: KEYSTORE_PASSWORD
          valueFrom:
            secretKeyRef:
              key: user.password
              name: kafka
        image: tools.testCompany.co.za:8093/local/tt--mongodb-map:0.0.7.0-SNAPSHOT
        name: test-mongodb-sink-posmon
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        volumeMounts:
        - mountPath: /app/resources
          name: properties
        - mountPath: /stores
          name: stores
          readOnly: true
      

谢谢

Helm 这样的模板工具可以让您从部署时设置中填充环境变量值。在 Helm 中,这看起来像:

env:
  - name: EVENTS_TOPIC
    value: {{ .Values.eventsTopic }}
  - name: GROUP_ID
    value: {{ .Values.groupId }}
  - name: INPUT_TOPIC
    value: {{ .Values.inputTopic }}

然后您可以使用不同的主题集多次部署它:

helm install alchemy . \
  --set eventsTopic=test.ops.proc-events \
  --set groupId=test-mongodb-sink-alchemy \
  --set inputTopic=test.raw.ptv.alchemy
helm install bloomberg . \
  --set eventsTopic=test.ops.proc-events \
  --set groupId=test-mongodb-sink-bloomberg \
  --set inputTopic=test.raw.pretrade.bloomberg

您也可以编写要使用主题集列表配置的 Helm 图表,并且只部署该集一次:

{{- $top := . -}}{{-/* because "range" overwrites "." */-}}
{{- $topic := range $topics -}}
---
apiVersion: v1
kind: Deployment
metadata:
  name: {{ $topic.name }}
spec:
  ...
    env:
      - name: EVENT_TOPIC
        value: {{ $top.Values.eventTopic }}{{/* common to all deployments */}}
      - name: GROUP_ID
        value: test-mongodb-sink-{{ $topic.name }}
      - name: INPUT_TOPIC
        value: {{ $topic.inputTopic }}

像这样写配置:

eventTopic: test.ops.proc-events
topics:
  - name: alchemy
    inputTopic: test.raw.ptv.alchemy
  - name: bloomberg
    inputTopic: test.raw.pretrade.bloomberg

并像这样部署:

helm install connector . -f topic-listing.yaml

在任何情况下,每个 pod 只需要一个容器。这有几个原因。如果主题列表发生变化,这使您可以创建或删除部署,而不会干扰其他主题;如果所有内容都在一个 pod 中,则您必须停止并重新启动所有内容,Kafka 可能需要一两分钟才能弄清楚发生了什么。在 Kafka 上下文中,您还可以 运行 与主题上的分区一样多的消费者,但实际上不会更多;如果您有一个非常繁忙的主题,您可以轻松地将部署的 replicas: 设置为多个分区的多个消费者,但如果所有内容都在一个 pod 中,您唯一的选择就是将所有内容一起扩展。

Is it wise to use multiple containers in one pod. Easy to distinguish, but as they are tightly coupled , i am guessing high chance of failure and not actually proper microservice design.

您很可能希望将它们部署为单独的服务,以便您可以独立于彼此更新或重新配置它们。

Should I create multiple deployments for each of these pipelines ? Would be very difficult to maintain as each will have different deployment configs.

Kustomizekubectl 中的一个内置工具,当您想在具有不同配置的多个环境中部署相同的清单时,这是一个不错的选择。除了 kubectl.

之外,此解决方案不需要其他工具

使用 Kustomize 部署到多个环境

目录结构:

base/
  - deployment.yaml      # fully deployable manifest - no templating
  - kustomization.yaml   # default values e.g. for dev environment
app1/
  - kustomization.yaml   # specific values for app1
app2/
  - kustomization.yaml   # specific values for app2

使用 Kustomization 的示例部署清单

这里,环境变量是从ConfigMap such that we can use configMapGenerator加载的。此文件是 base/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-sink
  namespace: test-apps
spec:
  template: // some fiels, e.g. labels are omitted in example
    spec:
      containers:
      - name: mongodb-sink
        image: mongodb-map:0.0.7.0-SNAPSHOT
        env:
          - name: MONGODB_HOST0
            value: test-mongodb-0.test-mongodb-headless.test-infra
          - name: MONGODB_HOST1
            value: test-mongodb-1.test-mongodb-headless.test-infra
          - name: GROUP_ID
            valueFrom:
              configMapKeyRef:
                name: my-values
                key: GROUP_ID
          - name: INPUT_TOPIC
            valueFrom:
              configMapKeyRef:
                name: my-values
                key: INPUT_TOPIC
      ...

同时添加一个 base/kustomization.yaml 文件来描述 configMapGenerator 和相关文件。

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml

configMapGenerator:
- name: my-values
  behavior: replace
  literals:
  - GROUP_ID=test-mongodb-sink-calypso
  - INPUT_TOPIC=test.raw.ptv.calypso
  ... # also add your other values

预览清单

kubectl kustomize base/

应用清单

kubectl apply -k base/

为 app1 和 app2 添加配置

对于 app1,我们现在想要使用我们在 base/ 中的清单,并且只是覆盖 app1 的不同之处.此文件是 app1/kustomization.yaml 并且与 app2/kustomization.yaml.

类似
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

bases:
- ../base

namePrefix: bloomberg-sink-   # this gives your Deployment a prefixed name

configMapGenerator:
- name: my-values
  behavior: replace
  literals:
  - GROUP_ID=test-mongodb-sink-bloomberg
  - INPUT_TOPIC=test.raw.pretrade.bloomberg
  ... # also add your other values

预览清单

kubectl kustomize app1/

应用清单

kubectl apply -k app1/

文档