【问题标题】:Helm convert data for nginx templateHelm 为 nginx 模板转换数据
【发布时间】:2021-09-27 23:02:35
【问题描述】:

我通过 helm 使用以下文件

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-cfg
data:
  default.conf: |-
  {{ .Files.Get "config/nginx.conf" | nindent 4 }}

我收到以下错误:

错误:ops/templates/config/nginx.conf 上的 YAML 解析错误:将 YAML 转换为 JSON 时出错:yaml:第 4 行:此上下文中不允许映射值

nginx 文件如下所示

nginx.conf

server {
    listen       80;
    listen  [::]:80;
    server_name: {{ print "kiftb." .Values.global.host | quote }} // this is the error line
...

带有sever_name 的行会产生错误。

知道怎么解决吗?

更新

正如@Evan 所建议的,我已尝试删除冒号,

server_name {{ print "kiftb." .Values.global.host | quote }}

我得到了一个错误:

error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead
helm.go:81: [debug] error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead

任何想法如何克服这个?有什么解决方法吗?

【问题讨论】:

  • 验证yaml文件的好地方yamllint.com
  • @user5756014 - 这不是问题,问题在于使用 helm 值

标签: json nginx kubernetes yaml kubernetes-helm


【解决方案1】:

尝试删除server_name之后的冒号。

server_name {{ print "kiftb." .Values.global.host | quote }}

...

【讨论】:

  • 谢谢我试了一下,我得到了不同的错误:error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead 并知道可能是什么问题?
  • @Alberto 抱歉,我之前没有发现这一点,但我认为您的操作前提存在缺陷。 Helm does not support the rendering of non-yaml files,这也是您之前遇到该错误的原因。您的第一个问题似乎来自 Helm 将 conf 文件解析为 yaml 文件(尽管冒号实际上是 conf 文件的无效语法)。您似乎以错误的方式解决问题,所以我会调查actual ngnix chart 的做法。
猜你喜欢
  • 2020-05-27
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
  • 2020-02-07
  • 2021-05-15
  • 1970-01-01
  • 2012-08-11
  • 2018-04-14
相关资源
最近更新 更多