<p>I know that I can define something like this to get the pod name in my containers:</p>

<pre><code>env:
- name: POD_NAME
  valueFrom:
     fieldRef:
       fieldPath: metadata.name
</code></pre>

<p>But when I run: <code>$kubectl get pods</code></p>

<p>I have a different result, something like: <code>uipod-5d6795db87-cxxkg</code> which corresponds to <code>&lt;replicatset name&gt;-cxxkg</code>. </p>

<p>Is it possible to get that full name (<code>uipod-5d6795db87-cxxkg</code>) as environnement variable? Instead of only the pod name (<code>uipod</code>).</p>

<p>Thanks a lot</p>

<p>You don't need to explicitly set environment variable with pod name, its already present inside pod as an environment variable called <code>HOSTNAME</code>.</p>

<p>For example</p>

<pre><code>$ kubectl run nginx --image=nginx
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectlrun --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created
$
$ kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7bb7cd8db5-kddbs   1/1     Running   0          12s
$
$ kubectl exec -it nginx-7bb7cd8db5-kddbs bash
root@nginx-7bb7cd8db5-kddbs:/#
root@nginx-7bb7cd8db5-kddbs:/# env | grep HOSTNAME
HOSTNAME=nginx-7bb7cd8db5-kddbs
root@nginx-7bb7cd8db5-kddbs:/#
</code></pre>

<p><em>NOTE: As you can see <code>HOSTNAME</code> environment variable already have the exact pod name set.</em></p>
