首页 > 解决方案 > Helm 为 nginx 模板转换数据

问题描述

我通过 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

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

标签: jsonnginxkubernetesyamlkubernetes-helm

解决方案


尝试删除之后的冒号server_name

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

...


推荐阅读