简体   繁体   English

如何在Helm for Kubernetes中循环使用不同的模板?

[英]How to loop different templates in Helm for Kubernetes?

I want to deploy multiple Deployments of Pods with different images, ports, etc. but with very similar other properties. 我想部署具有不同图像,端口等但具有其他非常相似属性的Pod部署。 So I want to declare a single deployment.yaml file that looks something like this 所以我想声明一个看起来像这样的单个deployment.yaml文件

{{- range .Values.types }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
...
{{- end }}

Where my values.yaml is 我的values.yaml在哪里

types:
  - foo
  - bar
  - baz

However, this only spins up a single Kubernetes Deployment when I helm install because everything is in one template file. 但是,当我helm install时,这只会启动一个Kubernetes部署,因为所有内容都在一个模板文件中。 Any ideas on how to do this? 有关如何执行此操作的任何想法?

Kubernetes generally uses YAML syntax, and that allows multiple "documents" to be in a single physical file with a --- delimiter before each one. Kubernetes通常使用YAML语法,并允许多个“文档”位于单个物理文件中,并在每个物理文件之前使用---分隔符。 Helm in turn generally operates by applying the templating to produce a plain-text file and in effect feeding it to kubectl apply . 然后,Helm通常通过应用模板来进行操作以生成纯文本文件,并有效地将其提供给kubectl apply

The upshot of this is that if you start each Kubernetes object description with the --- start-of-document delimiter, it should work: 这样做的结果是,如果您使用---文档开始定界符开始每个Kubernetes对象描述,它将起作用:

{{- range .Values.types }}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
...
{{- end }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM