helm的charts目录结构

版权声明:本文为博主原创文章,转载请注明来源。开发合作联系[email protected] https://blog.csdn.net/luanpeng825485697/article/details/82219197

Helm Chart 结构

Chart 目录结构

examples/
  Chart.yaml          # Yaml文件,用于描述Chart的基本信息,包括名称版本等
  LICENSE             # [可选] 协议
  README.md           # [可选] 当前Chart的介绍
  values.yaml         # Chart的默认配置文件
  requirements.yaml   # [可选] 用于存放当前Chart依赖的其它Chart的说明文件
  charts/             # [可选]: 该目录中放置当前Chart依赖的其它Chart
  templates/          # [可选]: 部署文件模版目录,模版使用的值来自values.yaml和由Tiller提供的值
  templates/NOTES.txt # [可选]: 放置Chart的使用指南

Chart.yaml 文件

name: [必须] Chart的名称
version: [必须] Chart的版本号,版本号必须符合 SemVer 2:http://semver.org/
description: [可选] Chart的简要描述
keywords:
  -  [可选] 关键字列表
home: [可选] 项目地址
sources:
  - [可选] 当前Chart的下载地址列表
maintainers: # [可选]
  - name: [必须] 名字
    email: [可选] 邮箱
engine: gotpl # [可选] 模版引擎,默认值是gotpl
icon: [可选] 一个SVG或PNG格式的图片地址

requirements.yaml 和 charts目录

requirements.yaml 文件内容:

dependencies:
  - name: example
    version: 1.2.3
    repository: http://example.com/charts
  - name: Chart名称
    version: Chart版本
    repository: 该Chart所在的仓库地址

Chart支持两种方式表示依赖关系,可以使用requirements.yaml或者直接将依赖的Chart放置到charts目录中。

templates 目录

templates目录中存放了Kubernetes部署文件的模版。
例如:

# db.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: deis-database
  namespace: deis
  labels:
    heritage: deis
spec:
  replicas: 1
  selector:
    app: deis-database
  template:
    metadata:
      labels:
        app: deis-database
    spec:
      serviceAccount: deis-database
      containers:
        - name: deis-database
          image: {{.Values.imageRegistry}}/postgres:{{.Values.dockerTag}}
          imagePullPolicy: {{.Values.pullPolicy}}
          ports:
            - containerPort: 5432
          env:
            - name: DATABASE_STORAGE
              value: {{default "minio" .Values.storage}}

关于template的详细内容,将在下文阐述。

模版语法扩展了 golang/text/template的语法:

# 这种方式定义的模版,会去除test模版尾部所有的空行
{{- define "test"}}
模版内容
{{- end}}

# 去除test模版头部的第一个空行
{{- template "test" }}

用于yaml文件前置空格的语法:

# 这种方式定义的模版,会去除test模版头部和尾部所有的空行
{{- define "test" -}}
模版内容
{{- end -}}

# 可以在test模版每一行的头部增加4个空格,用于yaml文件的对齐
{{ include "test" | indent 4}}

模版中包含了很多 {{}} ,这些 {{}} 中以.Values开头的会被替换成values.yaml中的值,.Release开头的会被替换成release相关的变量值,Release是内置变量中的一员。quote是一个function,当然还有很多其他的function。

这里为什么说默认值呢,因为在执行 helm install 时,可以通过 helm install –set tags.front-end=true –set subchart2.enabled=false 这种方式来改变实际的值。

内置变量

Release.Name: The name of the release (not the chart)
Release.Time: The time the chart release was last updated. This will match the Last Released time on a Release object.
Release.Namespace: The namespace the chart was released to.
Release.Service: The service that conducted the release. Usually this is Tiller.
Release.IsUpgrade: This is set to true if the current operation is an upgrade or rollback.
Release.IsInstall: This is set to true if the current operation is an install.
Release.Revision: The revision number. It begins at 1, and increments with each helm upgrade.
Chart: The contents of the Chart.yaml. Thus, the chart version is obtainable as Chart.Version and the maintainers are in Chart.Maintainers.
Files: A map-like object containing all non-special files in the chart. This will not give you access to templates, but will give you access to additional files that are present (unless they are excluded using .helmignore). Files can be accessed using {{index .Files “file.name”}} or using the {{.Files.Get name}} or {{.Files.GetString name}} functions. You can also access the contents of the file as []byte using {{.Files.GetBytes}}
Capabilities: A map-like object that contains information about the versions of Kubernetes ({{.Capabilities.KubeVersion}}, Tiller ({{.Capabilities.TillerVersion}}, and the supported Kubernetes API versions ({{.Capabilities.APIVersions.Has “batch/v1”)

全局变量

Helm的变量是有作用域的:父Chart可以访问子Chart的值,而子Chart不能访问父Chart的值:

猜你喜欢

转载自blog.csdn.net/luanpeng825485697/article/details/82219197