依赖管理
Chart 依赖关系
在
用requirements.yaml 来管理依赖关系
dependencies:
- name: apache
version: 1.2.3
repository: http://example.com/charts
- name: mysql
version: 3.2.1
repository: http://another.example.com/charts
- 该
name 字段是chart 的名称。 version 字段是chart 的版本。repository 字段是chart repo 的完整URL 。请注意,还必须使用helm repo add 添加该repo 到本地才能使用。
有了依赖关系文件,你可以通过运行
$ helm dep up foochart
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "local" chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "example" chart repository
...Successfully got an update from the "another" chart repository
Update Complete. Happy Helming!
Saving 2 charts
Downloading apache from repo http://example.com/charts
Downloading mysql from repo http://another.example.com/charts
当
charts/
apache-1.2.3.tgz
mysql-3.2.1.tgz
通过
requirements.yaml 中的alias 字段
除上述其他字段外,每个
# parentchart/requirements.yaml
dependencies:
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: new-subchart-1
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: new-subchart-2
- name: subchart
repository: http://localhost:10191
version: 0.1.0
在上面的例子中,我们将得到
subchart
new-subchart-1
new-subchart-2
requirements.yaml 中的tags 和condition 字段
除上述其他字段外,每个需求条目可能包含可选字段
-
Condition: condition 字段包含一个或多个YAML 路径(用逗号分隔) 。如果此路径存在于顶级父级的值中并且解析为布尔值,则将根据该布尔值启用或禁用chart 。只有在列表中找到的第一个有效路径才被评估,如果没有路径存在,那么该条件不起作用。 -
Tags: 标签字段是与此chart 关联的YAML 标签列表。在顶级父级的值中,可以通过指定标签和布尔值来启用或禁用所有带有标签的chart 。
# parentchart/requirements.yaml
dependencies:
- name: subchart1
repository: http://localhost:10191
version: 0.1.0
condition: subchart1.enabled, global.subchart1.enabled
tags:
- front-end
- subchart1
- name: subchart2
repository: http://localhost:10191
version: 0.1.0
condition: subchart2.enabled,global.subchart2.enabled
tags:
- back-end
- subchart2
# parentchart/values.yaml
subchart1:
enabled: true
tags:
front-end: false
back-end: true
在上面的示例中,所有带有标签的
--set
参数可使用来更改
helm install --set tags.front-end=true --set subchart2.enabled=false
Conditions ( 设置values) 会覆盖tags 配置。第一个存在的condition 路径生效,后续该chart 的condition 路径将被忽略。- 如果
chart 的某tag 的任一tag 的值为true ,那么该tag 的值为true ,并启用这个chart 。 Tags 和conditions 值必须在顶级父级的值中进行设置。tags:
值中的关键字必须是顶级关键字。目前不支持全局和嵌套tags:
表格。
依赖管理
所有使用
而使用
env:
- name: SERVICE_NAME
value: "{{ .Release.Name }}-{{ .Values.image.env.SERVICE_NAME }}"
这是使用了{{ .Values.image.env.SERVICE_NAME }}
的值是从
image:
env:
SERVICE_NAME: k8s-app-monitor-test
本地依赖
在本地当前
helm serve
将该
helm repo add local http://localhost:8879
在浏览器中访问 http://localhost:8879 可以看到所有本地的
然后下载依赖到本地。
helm dependency update
这样所有的charts
目录下。
共享
我们可以修改
$ helm package .
打包出
dependencies:
- name: mariadb
version: 0.6.0
repository: https://kubernetes-charts.storage.googleapis.com
使用