1

how can I create a yaml file for pod that get its name from a environment variables defined in yaml file.

I have tried this but it is not allowed.

metadata:
  generateName: $(HOSTNAME)
.
.
.

env: 
  - name: HOSTNAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
esxzawq
  • 121
  • 1
  • 10

1 Answers1

1

Kubernetes allows you to set environment variables using the values of other fields in the Pod definition that are only available at the time the Pod is initiated.

In your example you tried to set spec.nodeName instead of metadata.name. You config should look something like this:

  env:
    - name: MY_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name

Here you can find an official example of how to set it up.

Please let me know if that helped.