Helm 为 nginx 模板转换数据
Helm convert data for nginx template
我通过 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
知道如何克服这个问题吗?有什么解决方法吗?
尝试删除 server_name
之后的冒号。
server_name {{ print "kiftb." .Values.global.host | quote }}
...
听起来你把 conf 文件放在了错误的路径中。 Helm 将 ${chart_path}/templates/
中的所有文件作为模板或 tpl 文件处理,这些文件应在 YAML 文件中组成。所以基本上你面临的问题是 helm 试图将 ops/templates/config/nginx.conf
解析为模板文件,并且肯定会失败。
解决方案是:将您的 conf 文件移出路径 ops/templates
,使用 ops/config/nginx.conf
就可以了,您甚至不需要更改 configmap 脚本中的任何内容,它会起作用。
我通过 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
知道如何克服这个问题吗?有什么解决方法吗?
尝试删除 server_name
之后的冒号。
server_name {{ print "kiftb." .Values.global.host | quote }}
...
听起来你把 conf 文件放在了错误的路径中。 Helm 将 ${chart_path}/templates/
中的所有文件作为模板或 tpl 文件处理,这些文件应在 YAML 文件中组成。所以基本上你面临的问题是 helm 试图将 ops/templates/config/nginx.conf
解析为模板文件,并且肯定会失败。
解决方案是:将您的 conf 文件移出路径 ops/templates
,使用 ops/config/nginx.conf
就可以了,您甚至不需要更改 configmap 脚本中的任何内容,它会起作用。