原文:https://stackoverflow.com/questions/53973887/helm-simple-for-loop
[root@master templates]# ls
headless-srv.yaml _helpers.tpl out-srv.yaml statefulset.yaml ui-srv.yaml
[root@master templates]# cat out-srv.yaml
//range作用域无法直接读取values,提前定义
{{- $num := (.Values.stateSet.replicas | toString) | int }}
{{- $port := (.Values.ui.service.port | toString) | int }}
//range作用域
{{- range $index := untilStep 0 $num 1}}
---
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
myLabelName: "{{ $index}}-888888"
ports:
- protocol: TCP
port: {{ $port }}
targetPort: 9376
{{- end }}