gpt4 book ai didi

kubernetes - kubernetes 中是否有任何机制可以自动为特定 namespace 中的新 pod 添加注释?

转载 作者:行者123 更新时间:2023-12-05 05:45:19 30 4
gpt4 key购买 nike

我有一个命名空间,其中 Apache Airflow 不断创建新的短期 pod(< 1 分钟)。我希望所有这些新 pod 都自动用 aws.amazon.com/cloudwatch-agent-ignore: true 注释,这样就不会为这些 pod 创建 CloudWatch 指标(容器洞察力)。

我知道我可以使用 pod mutation hook 从气流端实现这一点,但为了争论起见,我们假设我无法控制该气流实例的配置

我见过 MutatingAdmissionWebhook,它似乎可以解决问题,但设置起来似乎需要相当大的努力。所以我正在寻找更多现成的解决方案,我想知道是否有一些“标准”准入 Controller 可以执行此特定用例,而无需部署 Web 服务器并实现 MutatingAdmissionWebhook 所需的 api。

有没有办法在 pod 创建时从 kubernetes 端添加该注释?注释必须“从一开始就存在”,而不是在 5 秒后添加,否则 cwagent 可能会在两者之间选择它pod 创建和正在添加的注释。

最佳答案

为了澄清,我正在发布社区 Wiki 答案。

你必须使用 aws.amazon.com/cloudwatch-agent-ignore: true注解。这意味着有一个 pod 将被 amazon-cloudwatch-agent/cwagent 忽略。

以下是如何将此注释添加到 Apache Airflow 的解决方案的摘录:

(...) In order to force Apache Airflow to add theaws.amazon.com/cloudwatch-agent-ignore: true annotation to the task/worker pods and to the pods created by the KubernetesPodOperator you will need to add the following to your helm values.yaml (assuming that you are using the "official" helm chart for airflow 2.2.3):

airflowPodAnnotations:
aws.amazon.com/cloudwatch-agent-ignore: "true"
airflowLocalSettings: |-
def pod_mutation_hook(pod):
pod.metadata.annotations["aws.amazon.com/cloudwatch-agent-ignore"] = "true"

If you are not using the helm chart then you will need to change the pod_template_file yourself to add the annotation and you will also need to modify the airflow_local_settings.py to include the pod_mutation_hook.

Here是您整个答案的链接。

关于kubernetes - kubernetes 中是否有任何机制可以自动为特定 namespace 中的新 pod 添加注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71420783/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com