Helm
安装:
下载地址:https://github.com/helm/helm/releases
解压:tar -zxvf helm-v3.4.1-linux-amd64.tar.gz
快捷:mv linux-amd64/helm /usr/local/bin/helm
修改repo源
helm repo add repo_name1 https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator
helm repo add gitlab https://charts.gitlab.io/
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
helm repo remove stable && helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
常用命令
helm install # 安装包
helm ls = helm list # 列表
helm uninstall # 卸载安装包
helm status xxx # 安装包的状态
helm get -h
helm search
helm repo list # 本地repo添加的列表
helm repo add name true:name # 添加仓库
helm repo update
helm repo remove
helm create xxx
helm package xxxx
三大概念
- Chart : Helm的包,包含了一个应用所有必须的资源等于docker镜像
- Repository: 放Chart的仓库等于docker仓库
- Release: 运行在集群中的实例等于container容器
创建chart
[root@k8s-master ~]# helm create mychart
Creating mychart
#即在当前目录创建了一个mychart文件夹
[root@k8s-master ~]# tree mychart/
mychart/
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ └── service.yaml
└── values.yaml
2 directories, 7 files
Chart.yaml 包含了chart的metadata,描述了Chart名称、描述信息与版本。
values.yaml:存储了模板文件变量。
templates/:记录了全部模板文件。
charts/:依赖chart存储路径。
NOTES.txt:给出了部署后的信息,例如如何使用chart、列出默认的设置等等
chart的安装方式
# chart安装有以下几种方式:
# 指定chart:
helm install stable/mariadb
# 指定打包的chart:
helm install ./nginx-1.2.3.tgz
# 指定打包目录:
helm install ./nginx
# 指定chart包URL:
helm install https://example.com/charts/nginx-1.2.3.tgz
# 查看charts默认配置
helm inspect values mychart
# 覆盖chart中的默认值,通过指定配置文件方式
helm install -f myvalues.yaml ./mychart
# 或者通过–set key=value形式
helm install --set name=prod ./mychart
找chart: helm search
helm 的搜索指令很好用,可以用来搜两种不同类型的源:
helm search hub:会去helm hub上搜一些其他大佬们共享出来的chart。
helm search repo:会搜那些你已经通过 helm repo add
添加到本地helm client的repository,这个搜索完全在搜本地数据,无需联外网。
在安装前做一些自定义操作
前面的安装都是走默认配置,有时候你可能会想做些自定义配置。
使用helm show values
查看这个chart都支持哪些可配置项
helm show values prometheus-community/kube-prometheus-stack
有两种方式在安装时传配置数据:
--values
(or-f
): 指定一个yaml文件,这个参数可以传递多个,写指令时,越靠右的拥有越高的优先级。--set
: 直接覆盖配置。
如果都用的话,set的值会被合并到value里,并且拥有更高优先级。
使用set复写的配置会被持久化到config map中,同时可以使用helm get values <release-name>
获取那些通过set设置进来的值,想清除通过set进来的值可以在运行helm upgrade 时带上 --reset-values
--set 的格式与限制
--set
选项可以不指定参数,也可以指定多个name/value 对, 最简单的写法一般是: --set name=value
. YAML的等价写法:
name: value
多个值用 ,
分割。 所以 --set a=b,c=d
yaml这里就变成了:
a: b
c: d
也有一些更复杂的形式,比如 --set outer.inner=value
会被识别成:
outer:
inner: value
列表可用 {
和 }
包裹。 比如, --set name={a, b, c}
对应的是:
name:
- a
- b
- c
到了 Helm 2.5.0,可以使用数组索引的方式去访问列表元素。比如 --set servers[0].port=80
就代表:
servers:
- port: 80
多值可以这样设置。 --set servers[0].port=80,servers[0].host=example
代表:
servers:
- port: 80
host: example
有时你可能需要在 --set
里使用一些特殊字符。你可以用 \
去做转义,比如 --set name=value1\,value2
的意思是:
name: "value1,value2"
类似的,你也可以给点儿做转义,这样写的 --set nodeSelector."kubernetes\.io/role"=master
会被理解成:
nodeSelector:
kubernetes.io/role: master
深层嵌套的结构如果用 --set
写起来可能会很复杂,所以Chart的编写者在设计变量时也要考虑其他使用者在使用 --set
进行赋值时书写的复杂度。
其他的安装方法
helm install
可以从多种源进行安装:
- Chart 的 repository (如上所述)
- 本地的Chart archive (
helm install foo foo-0.1.1.tgz
) - 一个未打包的Chart 路径 (
helm install foo path/to/foo
) - 一个完整的 URL (
helm install foo https://example.com/charts/foo-1.2.3.tgz
)
详细文档
https://www.kubernetes.org.cn/2711.html
https://whmzsu.github.io/helm-doc-zh-cn/