How to pass args to pods based on Ordinal Index in StatefulSets?

后端 未结 5 1216
再見小時候
再見小時候 2021-01-04 19:43

Is it possible to pass different args to pods based on their ordinal index in StatefulSets? Didn\'t find the answer on the StatefulSets documentation. Thanks!

5条回答
  •  走了就别回头了
    2021-01-04 20:18

    I found one less hacky way to pass in ordinal index into container using the lifecycle hooks

      containers:
      - name: cp-kafka
        imagePullPolicy: Always
        image: confluentinc/cp-kafka:4.0.0
        resources:
          requests:
            memory: "2Gi"
            cpu: 0.5
        ports:
        - containerPort: 9093
          name: server
          protocol: TCP
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh", "-c", "export KAFKA_BROKER_ID=${HOSTNAME##*-}"]
        env:
          - name: KAFKA_ZOOKEEPER_CONNECT
            value: zk-cs.default.svc.cluster.local:2181
          - name: KAFKA_ADVERTISED_LISTENERS
            value: PLAINTEXT://localhost:9093
    

提交回复
热议问题