将不同的 configmap 或 env 属性 传递给 pod,具体取决于它 运行 在哪个节点上
pass different configmap or env property to pod depending on which node it's running on
我正在尝试在我的 kubernetes 集群的多个节点中配置一个可以 运行 的 pod。
根据为 schedule/run Pod 选择的节点,Pod 所需的配置也不同。
例如,如果 pod 在节点 1 中结束 运行,则配置值(例如连接到某些外部服务的用户名)需要为 "user-node1"。
如果同一个 pod 在 node2 中结束 运行ning,我需要该配置值不同(例如 "user-node2".
理想情况下,我的 cluster/app 配置将只有一个,其中 user-node1 和 user-node2 都存在于某处,当我的 pod 被安排到 node1 或 node2 中的 运行 时,适当的配置被传递给 pod(我试图让 pod 不知道每个节点有多个配置)。
有什么办法可以实现吗?
这是非常具体的场景。您可以尝试使用 Admission Controllers - MutatingAdmissionWebhook.
之一
An admission controller is a piece of code that intercepts requests to the Kubernetes API server prior to persistence of the object, but after the request is authenticated and authorized. The controllers consist of the list below, are compiled into the kube-apiserver binary, and may only be configured by the cluster administrator. In that list, there are two special controllers: MutatingAdmissionWebhook and ValidatingAdmissionWebhook. These execute the mutating and validating (respectively) admission control webhooks which are configured in the API.
Admission controllers may be "validating", "mutating", or both. Mutating controllers may modify the objects they admit
在此选项中,您需要注入一些 lables or annotations to pod and then specify them also in your configmap。
此解决方案用于 Istio and was mentioned in .
中的示例
另一种选择是创建某种 Operator
,它将监视 namespaces
中的事件并修改 pod
.
此解决方案在 this article 中看起来像,但不是在 nodepool
中监视 nodes
,而是需要在 namespaces
中监视 pods
。
我正在尝试在我的 kubernetes 集群的多个节点中配置一个可以 运行 的 pod。
根据为 schedule/run Pod 选择的节点,Pod 所需的配置也不同。
例如,如果 pod 在节点 1 中结束 运行,则配置值(例如连接到某些外部服务的用户名)需要为 "user-node1"。 如果同一个 pod 在 node2 中结束 运行ning,我需要该配置值不同(例如 "user-node2".
理想情况下,我的 cluster/app 配置将只有一个,其中 user-node1 和 user-node2 都存在于某处,当我的 pod 被安排到 node1 或 node2 中的 运行 时,适当的配置被传递给 pod(我试图让 pod 不知道每个节点有多个配置)。
有什么办法可以实现吗?
这是非常具体的场景。您可以尝试使用 Admission Controllers - MutatingAdmissionWebhook.
之一An admission controller is a piece of code that intercepts requests to the Kubernetes API server prior to persistence of the object, but after the request is authenticated and authorized. The controllers consist of the list below, are compiled into the kube-apiserver binary, and may only be configured by the cluster administrator. In that list, there are two special controllers: MutatingAdmissionWebhook and ValidatingAdmissionWebhook. These execute the mutating and validating (respectively) admission control webhooks which are configured in the API.
Admission controllers may be "validating", "mutating", or both. Mutating controllers may modify the objects they admit
在此选项中,您需要注入一些 lables or annotations to pod and then specify them also in your configmap。
此解决方案用于 Istio and was mentioned in
另一种选择是创建某种 Operator
,它将监视 namespaces
中的事件并修改 pod
.
此解决方案在 this article 中看起来像,但不是在 nodepool
中监视 nodes
,而是需要在 namespaces
中监视 pods
。