【问题标题】:Error converting YAML to JSON: yaml: line 15: did not find expected alphabetic or numeric character将 YAML 转换为 JSON 时出错:yaml:第 15 行:未找到预期的字母或数字字符
【发布时间】:2022-02-23 22:08:48
【问题描述】:

我想为我的项目设置通配符子域,使用 k8s、nginx 入口控制器、helm chart:

ingress.yaml 文件中:

...
rules:
  - host: {{ .Values.ingress.host }}
...

values.yaml 文件中,我将主机example.local 更改为*.example.local

...
ingress:
  enabled: true
  host: "*.example.local"
...

然后,当我使用 helm chart 安装图表时:

Error: YAML parse error on example/templates/ingress.yaml: error converting YAML to JSON: yaml: line 15: did not find expected alphabetic or numeric character

我该如何解决?

感谢您的支持。

【问题讨论】:

    标签: kubernetes wildcard nginx-ingress helm3


    【解决方案1】:

    YAML 以一种特殊的方式处理以星号开头的字符串 - 这就是为什么带有通配符(如 *.example.local)的主机名会破坏 helm install 的入口。 为了被识别为字符串,ingress.yaml 文件中的值应该用" " 字符引用:

    ...
    rules:
      - host: "{{ .Values.ingress.host }}"
    ...
    

    这里还有一个选项 - 添加| quote

    ...
    rules:
      - host: {{ .Values.ingress.host | quote }}
    ...
    

    我已经重现了您的问题,这两个选项都正常工作。有关为 YAML 引用特殊字符的更多信息是 here

    【讨论】:

    • 感谢您的支持。您的选择有效
    【解决方案2】:

    在您的 ingress.yaml 中,在主机密钥周围加上引号。

    host: "{{ .Values.ingress.host }}"
    

    【讨论】:

      【解决方案3】:

      入口: 启用:真 主机:“*.example.local”

      您可能需要使用“---”而不是

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-08
        • 2020-03-10
        • 2019-12-13
        相关资源
        最近更新 更多