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

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

问题描述

我希望将服务部署到运行在多个区域上的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中不可用的信息.为了避免容器中的额外复杂性,您可以使用带有 Tobias的解决方案.边车将是豆荚中的另一个容器,其中连接到kubernetes API ,查询您要查找的信息(节点标签),并将输出写入共享卷.可以将其实现为初始化容器,或者将其实现为持续与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容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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