头盔values.yaml
文件是您可以在部署时配置图表的要点。一方面,您无法配置任何未在其中引用的内容.Values
;另一方面,您通常不希望 YAML 文件的每一行都是可配置的。
如果我要解决这个问题,我会从helm create https://docs.helm.sh/docs/helm/helm_create/一个新的图表。然后我会切换到templates
目录,将大部分样板移到一边(但保留生成的_helpers.tpl
文件),然后运行kompose convert https://kompose.io/user-guide/#kompose-convert。这将生成一组 YAML 文件,但没有 Helm 模板。
从这里我将编辑这些文件,使它们符合典型的 Helm 用法。查看原始文件来自helm create
(or 在 Helm 源码中 https://github.com/helm/helm/blob/main/pkg/chartutil/create.go) 举些例子。我希望编辑后的deployment.yaml
看起来像:
apiVersion: apps/v1
kind: Deployment
metadata:
{{-/* delete the Kompose annotations: and empty creationTimestamp: */}}
labels:
{{-/* get a standard set of labels from _helpers.tpl }}
{{- include "bookstore.labels" . | nindent 4 }}
{{-/* get a standard name from _helpers.tpl }}
name: {{ include "bookstore.fullname" . }}
应该包含什么内容values.yaml
文件,然后呢?这些是你需要配置的东西在部署时。如果您需要覆盖容器command:
or args:
,这些通常是固定的,但如果您需要提供某种凭据或主机名,这些可能会因部署而异。 (如果你helm install
将图表编辑两次,会是什么不同的安装之间?)helm create
模板使资源限制可配置,因为这些限制可能会根据实际工作负载而有很大差异:
# deployment.yaml (from helm/create.go linked above)
resources:
{{- toYaml .Values.resources | nindent 12 }}
# values.yaml (also from helm/create.go)
resources: {}
您可以在此处使用一组特定的值来部署它:
# values.dev.yaml
resources:
requests:
memory: 256Mi
limits:
memory: 1Gi
# values.prod.yaml
resources:
requests:
memory: 2Gi
limits:
memory: 4Gi
helm install bookstore . -f values.dev.yaml
例如,如果您保留了“哪个版本的 Kompose 生成了此文件”注释,则没有理由在环境之间更改该注释,因此您可以将其保留为固定字符串。