目录
1 简介
2 功能
3 参数
4 从父命令继承的命令
5 使用案例
5.1 helm dependency list
5.1.1 功能
5.1.2 语法格式
5.1.3 使用案例
5.2 helm dependency update
5.2.1 功能
5.2.2 语法格式
5.2.3 使用案例
5.3 helm dependency build
5.3.1 功能
5.3.2 语法格式
5.3.3 使用案例
6 注意事项
1 简介
Helm chart将依赖存储在'charts/'。对于chart开发者,管理依赖比声明了所有依赖的'Chart.yaml'文件更容易。
依赖命令对该文件进行操作,使得存储在'charts/'目录的需要的依赖和实际依赖之间同步变得很容易。
比如Chart.yaml声明了两个依赖:
# Chart.yaml
dependencies:
- name: nginx
version: "1.2.3"
repository: "https://example.com/charts"
- name: memcached
version: "3.2.1"
repository: "https://another.example.com/charts"
- 'name'是chart名称,必须匹配'Chart.yaml'文件中名称。
- 'version'字段应该包含一个语义化的版本或版本范围。
- 'repository'的URL应该指向Chart仓库。Helm希望通过附加'/index.yaml'到URL,应该能检索chart库索引。
注意:'repository'不能是别名。别名必须以'alias:'或'@'开头。
从2.2.0开始,仓库可以被定义为本地存储的依赖chart的目录路径。路径应该以"file://"前缀开头,比如:
# Chart.yaml
dependencies:
- name: nginx
version: "1.2.3"
repository: "file://../dependency_chart/nginx"
如果在本地检索依赖chart,不需要使用"helm add repo"将仓库加入到helm。该示例中也支持版本匹配。
2 功能
管理chart依赖
3 参数
#helm dependency -h
Manage the dependencies of a chart.
Helm charts store their dependencies in 'charts/'. For chart developers, it is
often easier to manage dependencies in 'Chart.yaml' which declares all
dependencies.
The dependency commands operate on that file, making it easy to synchronize
between the desired dependencies and the actual dependencies stored in the
'charts/' directory.
For example, this Chart.yaml declares two dependencies:
# Chart.yaml
dependencies:
- name: nginx
version: "1.2.3"
repository: "https://example.com/charts"
- name: memcached
version: "3.2.1"
repository: "https://another.example.com/charts"
The 'name' should be the name of a chart, where that name must match the name
in that chart's 'Chart.yaml' file.
The 'version' field should contain a semantic version or version range.
The 'repository' URL should point to a Chart Repository. Helm expects that by
appending '/index.yaml' to the URL, it should be able to retrieve the chart
repository's index. Note: 'repository' can be an alias. The alias must start
with 'alias:' or '@'.
Starting from 2.2.0, repository can be defined as the path to the directory of
the dependency charts stored locally. The path should start with a prefix of
"file://". For example,
# Chart.yaml
dependencies:
- name: nginx
version: "1.2.3"
repository: "file://../dependency_chart/nginx"
If the dependency chart is retrieved locally, it is not required to have the
repository added to helm by "helm add repo". Version matching is also supported
for this case.
Usage:
helm dependency [command]
Aliases:
dependency, dep, dependencies
Available Commands:
build rebuild the charts/ directory based on the Chart.lock file
list list the dependencies for the given chart
update update charts/ based on the contents of Chart.yaml
Flags:
-h, --help help for dependency
Global Flags:
--add-dir-header If true, adds the file directory to the header
--alsologtostderr log to standard error as well as files
--debug enable verbose output
--kube-context string name of the kubeconfig context to use
--kubeconfig string path to the kubeconfig file
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory
--log-file string If non-empty, use this log file
--log-file-max-size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
-n, --namespace string namespace scope for this request
--registry-config string path to the registry config file (default "/root/.config/helm/registry.json")
--repository-cache string path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
--repository-config string path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
Use "helm dependency [command] --help" for more information about a command.
4 从父命令继承的命令
--debug enable verbose output
--kube-apiserver string the address and the port for the Kubernetes API server
--kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--kube-as-user string username to impersonate for the operation
--kube-ca-file string the certificate authority file for the Kubernetes API server connection
--kube-context string name of the kubeconfig context to use
--kube-token string bearer token used for authentication
--kubeconfig string path to the kubeconfig file
-n, --namespace string namespace scope for this request
--registry-config string path to the registry config file (default "~/.config/helm/registry.json")
--repository-cache string path to the file containing cached repository indexes (default "~/.cache/helm/repository")
--repository-config string path to the file containing repository names and URLs (default "~/.config/helm/repositories.yaml")
5 使用案例
5.1 helm dependency list
5.1.1 功能
列举所有的chart中声明的依赖,该命令可以将chart包或chart目录作为输入,不会修改chart的内容。如果chart不能加载会产生错误。
5.1.2 语法格式
helm dependency list CHART [flags]
5.1.3 使用案例
helm dependency list
WARNING: no dependencies at charts
5.2 helm dependency update
5.2.1 功能
更新chart依赖信息
5.2.2 语法格式
helm dependency update CHART [flag]
5.2.3 使用案例
helm dependency update ./wordpress
5.3 helm dependency build
5.3.1 功能
基于 Chart.lock 文件重建 chart/ 目录,如果 Chart.lock 文件不存在,则执行 "helm dependency update" 命令。
5.3.2 语法格式
helm dependency build $CHART_PATH [flag]
5.3.3 使用案例
helm dependency build ./wordpress
6 注意事项
第一次下载依赖时,可以使用 helm dependency update 命令,它会将每个依赖项下载到指定图表的 charts/ 目录下:
$ helm dependency update $CHART_PATH
helm dependency update 命令从图表存储库中下载 .tgz 扩展名的 GZip 格式压缩的依赖项。这个命令还会生成 Chart.lock 的文件。Chart.lock 文件类似 Chart.yaml 文件。Chart.yaml 文件定义是否需要依赖项,Chart.lock 文件定义依赖项的实际状态。
Chart.lock 文件内容如下:
dependencies:
- name: mariadb
repository: https://charts.bitnami.com
version: 9.3.11
digest: xxxxx
generated: "2021-xxxx"
与其对应的 Chart.yaml 文件示例:
apiVersion: v2
version: 0.0.1
name: dependencies-demonstration
dependencies:
- name: mariadb
version: 9.x.x
repository: https://charts.bitnami.com
在 Chart.yaml 文件中,指定依赖的 mariadb 版本是 9.x.x,但在 Chart.lock 文件中,版本是 9.3.11,这是因为 Chart.yaml 文件用了通配符定义版本,Helm 会下载 9.x.x 的最新版本,而当前最新版本正是 9.3.11。
根据 Chart.lock 文件,Helm 可以在 charts/ 目录被删除或者需要重新构建时,自动下载依赖项:
$ helm dependency build $CHART_PATH
既然能够通过 helm dependency build 命令下载依赖项,就可以从我们的图表源码中删除 charts/ 目录,以减少代码仓库的大小。
随着功能迭代,总会产生新的版本。这时可以使用 helm dependency update 命令更新依赖项,它会下载最新的可用版,并重新生成 Chart.lock 文件。如果将来要下载 10.x.x 版本,或者希望将依赖项固定到特定版本,如 9.0.0,可以在 Chart.yaml 文件中定义,然后执行 helm dependency update 命令。