简体   繁体   English

如何获取运行我的 Web 应用程序的容器的 ID/名称来满足当前用户请求

[英]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.

相关问题 如何获取我的用户及其消息列表以及相关的当前用户 ID - how can get i users and their messages list with related current user id 如何使用 git 将 URL 获取到我当前分支的合并请求或拉取请求? - How can I get the URL to a merge request or a pull request of my current branch using git? 当前用户 ID 在退出后保持不变 | Firebase 认证 | Flutter Web - Current user id is persistent after signing out | Firebase Auth | Flutter Web 如何以编程方式在 Google 云运行 api 中获取当前项目 ID - How to programmatically get current project id in Google cloud run api 为什么 gcloud container clusters get-credentials 会弄乱我的 Linux 用户权限? - Why gcloud container clusters get-credentials messes up my Linux user permissions? 如何在 Dialogflow 实现中获取当前意图的名称? - How to get current intent's name in Dialogflow fulfillment? 获取当前文档的 ID Flutter / Firebase - Get ID of current document Flutter / Firebase 如何将分支名称中的问题 ID 添加到合并请求描述模板? - How to add issue ID from branch name to merge request description template? 如何获取 Web App 的 Firebase Analytics App Instance Id? - how to get Firebase Analytics App Instance Id for Web App? 如何获取GitLab中触发管道的用户id? - How to get the user id who triggers the pipeline in GitLab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM