<p>Having a .NET Core API running inside a docker container on a Kubernetes cluster: how to tell the API the name of the pod.</p>
<p>Is there anyway to forward or inject the information?</p>
<p>This could be usefull to pin issues down to pods by enriching logs or connections.</p>

monty
<p>The <code>Downward</code> API provides the way to expose information to containers.</p>
<p>Description from the <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>This page shows how a Pod can use environment variables to expose
information about itself to Containers running in the Pod. Environment
variables can expose Pod fields and Container fields.</p>
</blockquote>
<p>Refer <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables" rel="nofollow noreferrer">this example</a> to see how information is exposed as the environment variables on the containers.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: dapi-envars-fieldref
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ &quot;sh&quot;, &quot;-c&quot;]
      args:
      - while true; do
          echo -en '\n';
          printenv MY_NODE_NAME MY_POD_NAME MY_POD_NAMESPACE;
          printenv MY_POD_IP MY_POD_SERVICE_ACCOUNT;
          sleep 10;
        done;
      env:
        - name: MY_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: MY_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: MY_POD_SERVICE_ACCOUNT
          valueFrom:
            fieldRef:
              fieldPath: spec.serviceAccountName
  restartPolicy: Never
</code></pre>
<p>The script running inside the container can then access this information from the environment variable.</p>
