在helm中,template的用法
时间: 2024-03-24 18:36:33 浏览: 138
在Helm中,模板文件使用{{ }}
语法来替换变量、执行函数和控制流。以下是一些例子:
- 变量替换
apiVersion: v1
kind: Pod
metadata:
name: {{ .Values.podName }}
spec:
containers:
- name: my-container
image: {{ .Values.image }}
ports:
- containerPort: {{ .Values.containerPort }}
在上面的例子中,变量.Values.podName
和.Values.image
将被替换为相应的值。
- 函数调用
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-svc
spec:
selector:
app: {{ .Release.Name }}
ports:
- name: http
port: {{ .Values.servicePort }}
targetPort: {{ .Values.targetPort }}
在上面的例子中,函数.Release.Name
将返回Helm release的名称,可以用于生成唯一的服务名称。
- 控制流
{{- if .Values.enableService }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-svc
spec:
selector:
app: {{ .Release.Name }}
ports:
- name: http
port: {{ .Values.servicePort }}
targetPort: {{ .Values.targetPort }}
{{- end }}
在上面的例子中,如果变量.Values.enableService
为真,则生成一个服务的定义,否则不生成。
通过使用模板,我们可以根据不同的参数值生成不同的 Kubernetes YAML 文件,并且可以灵活控制生成的内容。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)