SID :
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 /app/deploy(body contains app_id)
request is handled by POD1
.
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 kubernetesDiscoveryClient.getCurrentPOD()
, something of this sort.
SID :
This worked for me.
podName = Optional.ofNullable(System.getenv("HOSTNAME"));