Kubernetes PODs hostname as env

8/21/2018

I have suchlike problem:

    spec:
  hostname: kafka
  containers:
  - name: kafka
    image: registry/wurstmeister:latest
    imagePullPolicy: Always
    restartPolicy: Always
    env:
      - name: HOSTNAME_COMMAND
        valueFrom:
          fieldRef: {fieldPath: metadata.name}
      - name: KAFKA_ADVERTISED_LISTENERS
        value: INSIDE://:9092,OUTSIDE://_${HOSTNAME_COMMAND}:9094

First HOSTNAME_COMMAND resolves successfully, so I see the pod's hostname. I need to have the same for the second HOSTNAME_COMMAND, so I need to see something like this:

value: INSIDE://:9092,OUTSIDE://_kafka-6b97669c5c-lhfp7:9094

Thank you.

-- user37033
apache-kafka
api
kubernetes

1 Answer

8/21/2018

You can use $(ENV_NAME) format inside other config, The details is here, Using environment variables inside of your config.

-- Daein Park
Source: StackOverflow