【问题标题】:How to annotate pods of an Ingress Controller using Helm in Kubernetes (AKS)?如何在 Kubernetes (AKS) 中使用 Helm 注释 Ingress Controller 的 pod?
【发布时间】:2021-01-30 04:12:58
【问题描述】:

在 Azure AKS 上运行 helm chart 打包容器时,我正在尝试自动注释 pod(编辑:入口控制器 pod)以在 Scalyr 中设置自定义日志解析器。我可以自动注释服务,但无法自动注释 pod。使用 kubectl 手动执行此操作:

kubectl annotate pod nginx-ingress-ingress-nginx-controller-yyy-xxx --overwrite log.config.scalyr.com/attributes.parser=<my_scalyr_parser_name>

很好,但是当我的 pod 终止时,我会丢失我的注释,并且 Scalyr 可能会丢失一些日志。还是入口 nginx pods IDDQD(不朽)?所以我试图以某种方式自动化它。

我已经尝试将它添加到 values.yaml

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    log.config.scalyr.com/attributes.parser: "<my_scalyr_parser_name>"

但它只是放在 ingress.yaml 中的元数据注释中

kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "myservice.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}

这会导致服务的注释。但是,我需要在 pod 上进行注释,以便 Scalyr 使用我的自定义解析器,而不是在服务中。

另一种方法是在安装 nginx-ingress 时硬做:

helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.replicaCount=3 --set-string controller.pod.annotations.'log\.config\.scalyr\.com/attributes\.parser'="<my_scalyr_parser_name>"
--set-string controller.service.annotations.'service\.beta\.kubernetes\.io/azure-load-balancer-internal'="true" 

当我设置 controller.service.annotations 时,我会在服务上获得注释,但 controller.pod.annotations 会被忽略(我在 nginx 文档中找到了 controller.pod.annotations)。

那我还能做什么呢?

【问题讨论】:

    标签: azure nginx kubernetes kubernetes-helm azure-aks


    【解决方案1】:

    您应该可以使用values.yaml 来完成此操作,就像您尝试使用ingress 一样:

    controller:
      podAnnotations:
        log.config.scalyr.com/attributes.parser: "<my_scalyr_parser_name>"
    

    由于某种原因,变量的键是controller.podAnnotations而不是controller.pod.annotations

    【讨论】:

    • 是的,看看这个 values.yaml github.com/kubernetes/ingress-nginx/blob/…
    • 当我将这些行粘贴到 values.yaml 中时,我的 CD 管道中出现错误:升级失败:错误验证“”:错误验证数据:ValidationError(Ingress):未知字段“控制器” io.k8s.api.networking.v1beta1.Ingress 我也尝试将代码放入 ingress.yaml 但它也不起作用。但是,使用带有 controller.podAnnotations 而不是 controller.pod.annotations 的 helm CLI 效果很好,它解决了我的问题 :) 谢谢!
    • 所以使用 podAnnotations 的完整 helm 命令是: helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.replicaCount=3 --set-string controller.podAnnotations.'log\ .config\.scalyr\.com/attributes\.parser'="" --set-string controller.service.annotations.'service\.beta\.kubernetes\.io/azure-load-balancer-internal '="真"
    猜你喜欢
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2022-01-08
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多