We are using Dockers and Kubernets to containerize my .Net web application and scale up to 8-9 replicas. So we installed Dockers (in my Win 10 machine) and used Linux containers.
Orchestration is done by Kubernets. I would like to get the name/id of the container in which my web application is running to serve the current user request.
Could not find a way to get the id/name of the container from my .Net Web application. Please share me your thoughts on this.
Regards, Hari
You can expose Pod fields as environment variables, the field metadata.name
will contain the name of the Pod.
Documentation and example: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-container-fields-as-values-for-environment-variables
Edit: You can also use System.Environment.MachineName
as @vahdet commented earlier. The hostname of the container is the pod id.