Helm 模板中可以訪問的頂級對象
- Release
- Values
- Chart
- Files
- Capabilities
- Template
Release對象
對象名 | 描述 |
---|---|
Release.Name |
Release 名稱 |
Release.Time |
Release 時間 |
Release.Namespace |
Release 的 namespace |
Release.Service |
Release 服務的名稱(總是Tiller) |
Release.Revision |
Release 版本號,從 1 開始,每次 helm upgrade 時遞增1 |
Release.IsUpgrade |
如果當前操作是升級或回滾,則設置爲true。 |
Release.IsInstall |
如果當前操作是安裝,則設置爲true。 |
Values對象
從 values.yaml
文件和用戶提供的文件傳入模板的值。默認情況下,Values 是空的。在values.yaml文件中,可以定義任何想要給模板文件訪問的內容。
values.yaml文件
values對象的值四種來源
- chart包values.yaml文件
- 如果包含子chart包,父chart包中的value.yaml中定義的值,將覆蓋子chart包。
- 可以使用
-f
參數傳遞值到chart包的values.yaml中。如:(helm install -f myvals.yaml ./mychart
) - 使用命令行傳入指定的值,如:(
helm install --set foo=bar ./mychart
)
四種值的優先級:
4>3>2>1,高優先級將覆蓋低優先級中定義的相同key
對應的value
。
刪除value.yaml中的key
如果您需要從默認值中刪除一個鍵,可以覆蓋該鍵的值爲 null,在這種情況下,Helm 將從覆蓋值合併中刪除該鍵。
Chart對象
Chart.yaml
文件的內容。Chart.yaml中的定義任何數據都使用Chart對象訪問。如{{.Chart.Name}}-{{.Chart.Version}}
Chart.yaml中可以包含以下字段
apiVersion: The chart API version, always "v1" (必須參數)
name: The name of the chart (必須參數)
version: A SemVer 2 version (必須參數)
kubeVersion: A SemVer range of compatible Kubernetes versions (可選參數)
description: A single-sentence description of this project (可選參數)
keywords:
- A list of keywords about this project (可選參數)
home: The URL of this project's home page (可選參數)
sources:
- A list of URLs to source code for this project (可選參數)
maintainers: # (可選參數)
- name: The maintainer's name (required for each maintainer)
email: The maintainer's email (optional for each maintainer)
url: A URL for the maintainer (optional for each maintainer)
engine: gotpl # The name of the template engine (optional, defaults to gotpl)
icon: A URL to an SVG or PNG image to be used as an icon (optional).
appVersion: The version of the app that this contains (optional). This needn't be SemVer.
deprecated: Whether this chart is deprecated (optional, boolean)
tillerVersion: The version of Tiller that this chart requires. This should be expressed as a SemVer range: ">2.0.0" (optional)
Files對象
用於訪問在chart包中自定義的一些文件,無法使用它來訪問模板文件。
對象名 | 描述 |
---|---|
Files.Get | 按名稱獲取文件的函數,如:(.Files.Get config.ini )獲取config.ini文件 |
Files.GetBytes | 將文件內容作爲字節數組而不是字符串獲取的函數。這對於像圖片這樣的東西很有用。 |
Capabilities
提供了有於 Kubernetes 集羣支持的功能的信息。
對象名 | 描述 |
---|---|
Capabilities.APIVersions | 集羣版本信息 |
Capabilities.APIVersions.Has $version | 指示是否在羣集上啓用了版本(batch/ v1) |
Capabilities.KubeVersion | 提供了查找Kubernetes版本的方法。可以獲取到 Major ,Minor ,GitVersion ,GitCommit ,GitTreeState ,BuildDate ,GoVersion ,Compiler 和Platform 。 |
Capabilities.TillerVersion | 提供了查找Tiller版本的方法。可以獲取到SemVer , GitCommit , and GitTreeState . |
Template對象
包含當前正在執行的模板的信息。
對象名 | 描述 |
---|---|
Name | 當前模板的namespace 文件路徑(例如mychart / templates / template.yaml) |
BasePath | 當前 chart 模板目錄的namespace 路徑(例如 mychart/templates)。 |