【问题标题】:Kubectl patch adding extra "-" characterKubectl 补丁添加额外的“-”字符
【发布时间】:2019-12-09 01:45:49
【问题描述】:

我正在尝试使用 kubectl 补丁向我的 k8s nginx 入口添加额外的注释。

这是我开始的入口:

apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    annotations:
      field.cattle.io/publicEndpoints: '[{"stuff:false}]'
      kubernetes.io/ingress.class: nginx-external
    creationTimestamp: "2019-02-25T20:38:29Z"
    generation: 1

这是我正在应用的补丁文件ingress_annotation.yaml

metadata:
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:80;
      proxy_hide_header l5d-remote-ip;
      proxy_hide_header l5d-server-id;

我通过运行kubectl patch ingress kibana --patch "$(cat ingress_annotation.yaml)" 应用此补丁。

当我应用它时,它确实将注释添加到入口,当我运行kubectl get ingress <my_ingress> -o yaml 时看起来像这样:

apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    annotations:
      field.cattle.io/publicEndpoints: '[{"Stuff:false}]'
      kubernetes.io/ingress.class: nginx-external
      nginx.ingress.kubernetes.io/configuration-snippet: |-
        proxy_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:80;
        proxy_hide_header l5d-remote-ip;
        proxy_hide_header l5d-server-id;
    creationTimestamp: "2019-02-25T20:38:29Z"
    generation: 1

注意nginx.ingress.kubernetes.io/configuration-snippet: | 后面的额外"-" 字符。我不确定这个角色来自哪里或它在这里做什么。谁能帮我解释一下,或者我可以如何防止这个字符被添加到我的注释中?

【问题讨论】:

    标签: kubernetes annotations kubectl kubernetes-ingress nginx-ingress


    【解决方案1】:

    这是YAML syntax,可能是 kubectl 自动添加的:

    - 指示符:删除块后多余的换行符

    content: |-
       Arbitrary free text without newlines after it
    

    【讨论】:

    • 谢谢,有道理。
    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 2020-12-14
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2013-08-30
    相关资源
    最近更新 更多