用同一个deployment.yml文件的顶部在temp中定义标签-
{{- define "chart.labels" }}
version: v1.0
method: http
internet: enabled
{{- end }}我在模板文件夹里有deployment.yml文件-
apiVersion: apps/v1
kind: Deployment
metadata:
name: app1-deployment
namespace: {{ .Values.global.namespace }}
labels:
app: app1
type: microservice1
spec:
replicas: 3
selector:
matchLabels:
app: app1
type: microservice1
strategy:
type: {{ .Values.global.strategytype }}
template:
metadata:
labels:
app: app1
type: microservice1
{{- template "chart.labels" }}这两种方法-一种来自关键字模板(下面代码的最后一行)
和第二个包含关键字,我试图调用模板。
{{include "chart.labels" . | indent 8 }}YAML错误: YAML解析图表/模板/部署. YAML上的错误:将YAML转换为JSON的错误: yaml:第27行:未找到预期键helm.go:81:调试错误将YAML转换为JSON: yaml:第27行:未在图表/模板/部署.YAML
helm.sh /helm/v3/pkg/Relaseutil.SortManifest helm.sh上找到预期的密钥YAML解析错误/helm/v3/pkg/releaseutil/manifest_sorter.go:106 helm.sh/helm/v3/pkg/action.(*Configuration).renderResources helm.sh/helm/v3/pkg/action/action.go:165 helm.sh/helm/v3/pkg/action。(*安装).Run helm.sh/helm/v3/pkg/action/install.go:247
YAML错误: YAML解析图表/模板/部署. YAML上的错误:将YAML转换为JSON: yaml:第29行:在此上下文中不允许映射值-- helm.go:81:调试错误,将YAML转换为JSON: yaml:第29行:在此上下文中不允许YAML解析值,YAML解析图表/模板/部署.YAML
helm.sh/helm/v3/pkg/helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:106 helm.sh/helm/v3/pkg/action.(*Configuration).renderResources helm.sh/helm/v3/pkg/action/action.go:165 helm.sh/helm/v3/pkg/action。(*安装).Run helm.sh/helm/v3/pkg/action/install.go:247 main.runInstall
我在这里错过了什么?
发布于 2021-06-29 12:14:09
你需要跟随理智的缩进。你有:
{{- define "chart.labels" }}
version: v1.0
method: http
internet: enabled
{{- end }}注意,在下面的chart.labels定义中没有双重空间。
以下工作如下:
{{- define "chart.labels" }}
version: v1.0
method: http
internet: enabled
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "test.fullname" . }}
labels:
{{- include "test.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "test.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "test.selectorLabels" . | nindent 8 }}
{{include "chart.labels" . | nindent 8 }}编辑:或者只更改9,以匹配模板元中的chart.labels,如下所示:
{{include "chart.labels" . | nindent 6 }}https://stackoverflow.com/questions/68178304
复制相似问题