如何解决HELM脚本在json值上循环
我想用主机及其值准备入口
示例值文件:
hosts:
test1.test.top: {
"serviceName": "httpd-echo","servicePort": "5678"
}
test2.test.top: {
"serviceName": "httpd-echo2","servicePort": "5678"
}
试图将其应用于模板:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: {{ include "ingress.fullname" . }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
rules:
{{ range $key,$value := .Values.hosts }}
- host: {{ $key }}
http:
paths:
- backend:
{{- with .Values.hosts.$value }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{ end }}
但是有一个错误:
错误:在(general-ingress / templates / ingress.yaml:28)解析错误:错误 字符U + 0024'$'
请您提供示例,说明我如何实现它
解决方法
是否需要将值定义为json?如果是,则需要将它们声明为
hosts:
test1.test.top: |
{
"serviceName": "httpd-echo","servicePort": "5678"
}
test2.test.top: |
{
"serviceName": "httpd-echo2","servicePort": "5678"
}
如果您的values.yaml可以像
hosts:
test1.test.top:
serviceName: httpd-echo
servicePort: 5678
test2.test.top:
serviceName: httpd-echo2
servicePort: 5678
定义入口的一种选择是
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: {{ include "ingress.fullname" . }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
rules:
{{- range $key,$value := .Values.hosts }}
- host: {{ $key }}
http:
paths:
- backend:
{{- $value | toYaml | nindent 12 }}
{{- end }}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。