3

I'd like to get the instance ID (e.g. AWS EC2 instance ID like i-19a9fa9s8df9a8, not the private dns node name) of where my pod is running from within my k8s config file, but couldn't find any documentation on how to do that. Anybody know how to use the reportingInstance field in https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#event-v1-core?

I'm getting this error:

The DaemonSet  is invalid:
spec.template.spec.containers[0].env[8].valueFrom.fieldRef.fieldPath: 
Invalid value: "core.reportingInstance": 
error converting fieldPath: field label not supported: core.reportingInstance

This is what I tried:

    - name: INSTANCE_ID
      valueFrom:
        fieldRef:
          fieldPath: core.reportingInstance

I already have this in my yaml file but that gives the private dns name not the instance ID

   - name: NODE_NAME
      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName
user3226932
  • 2,042
  • 6
  • 39
  • 76

1 Answers1

0

Let me answer this with my understanding of your question. i think you want your node name value set as env variable in your container. If this is true you can use below code for that

 - name: Node_Name
      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName

If you want some other information about pod or container, please understand that you can get only limited information within container using downward api and that is limited to below mentioned field.

 fieldRef     <Object>
 Selects a field of the pod: supports metadata.name, metadata.namespace,
 metadata.labels, metadata.annotations, spec.nodeName,
 spec.serviceAccountName, status.hostIP, status.podIP.


resourceFieldRef     <Object>
 Selects a resource of the container: only resources limits and requests
 (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu,
 requests.memory and requests.ephemeral-storage) are currently supported.
  • no, i want the instance id, not the name of the node, for example for an AWS EC2 instance, it has an instance id and a private dns (node name), i want the instance id, i have the updated the question with this info now – user3226932 Feb 05 '19 at 17:42