Empty variable when using `status.hostIP` as reference field for my env variable in kubernetes

2.1k views Asked by At

I'm deploying a kubernetes pod using helm v3, my kubectl client and server are above 1.7 so it should support reference fields. However when i deploy, the value is just empty.

using

environment:
  - name: DD_AGENT_HOST
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP

Where the DD_AGENT_HOST is my env variable that should be given the host ip.

Any idea on why this might be happening?

2

There are 2 answers

0
Maxim On BEST ANSWER

Had to add it this to the container specification directly, not passing from an env and using include from helm as that doesn't work

0
vladbph On

The issue is related to helm app deployment template(IF you use one). For instance, if you have deployment.yaml with

      env:
      {{- range .Values.env }}
        - name: {{ .name }}
          value: {{ .value | quote }}
      {{- end }}

And one of env values is valueFrom, you have to add explicitly (unless there is a nicer way of doing it):

        - name: DD_AGENT_HOST
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP

Otherwise copy of the range above will not use valueFromand as a result DD_AGENT_HOST will be empty