将节点标签注入 Kubernetes pod [英] Inject node labels into Kubernetes pod

查看:26
本文介绍了将节点标签注入 Kubernetes pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将服务部署到在多个区域上运行的 Kubernetes 集群,并希望能够使用环境变量将区域/区域标签注入到我的 pod 中.

I am looking to deploy services to a Kubernetes cluster running over multiple zones and would like to be able to inject the region/zone labels into my pods using environment variables.

我已经研究了向下的 API,但是这似乎只允许您从 pod/服务而不是从您运行 pod 的节点注入标签/元数据.

I have looked into the downward API however this only seems to allow you to inject labels/metadata from the pod/service and not from the node you are running the pod on.

如果无法注入节点标签,我想到的另一种解决方案是让容器查询 kubernetes/AWS API 以获取此信息,但这意味着给我的容器增加了相当多的复杂性.

If there is no way to inject the node labels another solution I thought about was having the container query the kubernetes/AWS API to fetch this information however that would mean adding quite a lot of complexity to my containers.

推荐答案

我想过让容器查询 kubernetes/AWS API 来获取这些信息,但这意味着给我的容器增加了相当多的复杂性.

I thought about was having the container query the kubernetes/AWS API to fetch this information however that would mean adding quite a lot of complexity to my containers.

这是目前推荐的获取向下 API 中不可用的信息的方法.为了避免容器中的额外复杂性,您可以使用带有 托比亚斯的解决方案.sidecar 将是 pod 中的一个额外容器,它 连接到 kubernetes API,查询您要查找的信息(节点标签),并将输出写入共享卷.这可以实现为 init 容器,或一个 sidecar持续与 API 同步.

This is currently the recommended approach for getting information not available in the downward API. To avoid the additional complexity in your containers, you could use a "sidecar" with a variation on Tobias's solution. The sidecar would be an additional container in the pod, which connects to the kubernetes API, queries the information you're looking for (node labels), and writes the output to a shared volume. This could be implemented as an init container, or a sidecar that continuously syncs with the API.

这篇关于将节点标签注入 Kubernetes pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆