[英]How to get the id/name of the container in which my web application is running to serve the current user request
We are using Dockers and Kubernetes to containerize my.Net web application and scale up to 8-9 replicas.我们正在使用 Dockers 和 Kubernetes 来容器化 my.Net Web 应用程序并扩展到 8-9 个副本。 So we installed Dockers (in my Win 10 machine) and used Linux containers.
所以我们安装了 Dockers(在我的 Win 10 机器上)并使用了 Linux 容器。
Orchestration is done by Kubernetes.编排由 Kubernetes 完成。 I would like to get the name/id of the container in which my web application is running to serve the current user request.
我想获取运行我的 Web 应用程序的容器的名称/ID 以服务于当前用户请求。
Could not find a way to get the id/name of the container from my.Net Web application.找不到从 my.Net Web 应用程序获取容器 ID/名称的方法。 Please share me your thoughts on this.
请与我分享您对此的看法。
Regards问候
You can expose Pod fields as environment variables, the field metadata.name
will contain the name of the Pod.您可以将 Pod 字段公开为环境变量,字段
metadata.name
将包含 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文档和示例: 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.编辑:您也可以使用
System.Environment.MachineName
正如 @vahdet 之前评论的那样。 The hostname of the container is the pod id.容器的主机名是 pod id。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.