简体   繁体   English

如何在 k8s 的 configmap 中使用节点 ip

[英]How to use a node ip inside a configmap in k8s

I want to inject the value of k8s 'node ip' to a config map when a pod gets created.我想在创建 pod 时将 k8s 'node ip' 的值注入到配置 map 中。 Any way how to do that?有什么办法吗?

A configmap is not bound to a host (multiple pods on different hosts can share the same configmap). configmap 不绑定到主机(不同主机上的多个 pod 可以共享同一个 configmap)。 But you can get details in a running pod.但是您可以在运行的 pod 中获取详细信息。 You can get the host IP the following way in an environment variable.您可以通过以下方式在环境变量中获取主机 IP。 Add the following in your pods spec section:在您的 pod 规范部分添加以下内容:

env:
- name: MY_NODE_IP
  valueFrom:
    fieldRef:
      fieldPath: status.hostIP

Details about passing other values to env vars can be found in the official documentation .有关将其他值传递给 env vars 的详细信息可以在官方文档中找到。

Unfortunately you can't get the hostIP in a volume, as the downwardAPI doesn't have access to status.hostIP ( docu )不幸的是,您无法在卷中获取主机 IP,因为 downAPI 无权访问status.hostIP ( docu )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM