<p>I am deploying my Microservices on Kubernetes Cluster. Every Application has 4 replicas or PODS. For a REST API in 1 application, I want to track which POD addressed my request. e.g. my <code>/app/deploy(body contains app_id)</code> request is handled by <code>POD1</code>.</p>

<p>For the same, I have imported Kubernetes jar in my application. In my code, I want to check the current POD on which this code is running.
I want an API like <code>kubernetesDiscoveryClient.getCurrentPOD()</code>, something of this sort.</p>

SID
<p>You do not need Kubernetes Jar in your Java application. A simple <code>System.getenv("HOSTNAME")</code> will give you the name of your Pod. Works on all platform, and since Kubernetes version 1.6 at least.</p>

<p>More formally, you could use the following in your Kube spec (<a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables" rel="noreferrer">detailed reference</a>), and then read the environment using <code>System.getenv("MY_POD_NAME")</code> in Java.</p>

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