我可以在脚本中使用 helm chart 中的变量吗?
Could I use variables in helm chart in script?
我有这样的东西
args: ["-c", "while [ $(curl -sw '%{http_code}' "http://{{ include "backend.name" . }}-{{ .Release.Namespace }}:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done"
它应该 运行 正确吗?或者我有没有机会在不部署的情况下检查它?
您可以使用两个选项。
如下:
- 变量和结构在values.yaml中定义,然后在需要使用的地方直接引入
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "test"
spec:
template:
spec:
containers:
- name: "test"
image: "test:v1.0"
{{- if .Values.args }}
args:
{{ toYaml .Values.args | nindent 12 }}
{{- end }}
values.yaml
args:
- -c
- while [ $(curl -sw 'http://xx.xx.xx.xx' "http://xx.xx.xx.xx:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done
- 在deployment.yaml中定义结构,然后在values.yaml中定义变量,然后部署引用值
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "test"
spec:
template:
spec:
containers:
- name: "test"
image: "test:v1.0"
{{- if .Values.args }}
args:
- {{ .Values.args.lv }}
- while [ $(curl -sw '{{ .Values.args.code }}' "http://{{ include "backend.name" . }}-{{ .Release.Namespace }}:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done
{{- end }}
values.yaml
args:
lv: -c
code: http://0.0.0.0
我有这样的东西
args: ["-c", "while [ $(curl -sw '%{http_code}' "http://{{ include "backend.name" . }}-{{ .Release.Namespace }}:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done"
它应该 运行 正确吗?或者我有没有机会在不部署的情况下检查它?
您可以使用两个选项。
如下:
- 变量和结构在values.yaml中定义,然后在需要使用的地方直接引入
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "test"
spec:
template:
spec:
containers:
- name: "test"
image: "test:v1.0"
{{- if .Values.args }}
args:
{{ toYaml .Values.args | nindent 12 }}
{{- end }}
values.yaml
args:
- -c
- while [ $(curl -sw 'http://xx.xx.xx.xx' "http://xx.xx.xx.xx:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done
- 在deployment.yaml中定义结构,然后在values.yaml中定义变量,然后部署引用值
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "test"
spec:
template:
spec:
containers:
- name: "test"
image: "test:v1.0"
{{- if .Values.args }}
args:
- {{ .Values.args.lv }}
- while [ $(curl -sw '{{ .Values.args.code }}' "http://{{ include "backend.name" . }}-{{ .Release.Namespace }}:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done
{{- end }}
values.yaml
args:
lv: -c
code: http://0.0.0.0