0
点赞
收藏
分享

微信扫一扫

helm 使用方法

哈哈我是你爹呀 2022-03-11 阅读 175


harbor管理helm-chart
harbor安装的时候默认没有helm charts的仓库,启用 harbor 的 chart repository 服务

docker-compose stop
./install.sh --with-chartmuseum



添加仓库
helm repo add --username admin --password Senyint.rh13579 harbor http://192.168.15.198/chartrepo/superman


安装Chart
helm install --username=admin --password=Senyint.rh13579 --version 0.1.1 harboprepo/mychart --generate-name


创建chart
helm create fengjian

打包
[root@master1 helm3]# helm package fengjian
Successfully packaged chart and saved it to: /tmp/helm3/fengjian-0.1.0.tgz



helm repo add aliyuncs https://apphub.aliyuncs.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add stable http://mirror.azure.cn/kubernetes/charts/

列出所有chart所有的包
helm search repo

列出 stablechart所有的包
helm search repo stable

列出所有chart mysql包
helm search repo mysql

#列出stable mysql包
helm search repo stable/mysql


列出stable chart中 mysql包
helm search repo stable | grep mysql

helm show

Available Commands:
all show all information of the chart
chart show the chart's definition
crds show the chart's CRDs
readme show the chart's README
values show the chart's values


查看 stable/mariadb 详细信息
helm show all stable/mariadb

helm show chart stable/mariadb

安装
helm install stable/mysql #默认生成一个名字 例如mysql-12345
指定名字
helm install mariadb stable/mysql

[root@harbor mysql]# helm ls
NAME NAMESPACE REVISION
mariadb default 1

更新
helm upgrade mariadb stable/mysql


指定values.yaml 值
[root@harbor mysql]# helm install tidb -f 1.yaml stable/mysql

[root@harbor mysql]# cat 1.yaml
mysqlUser: feng
mysqlDatabase: feng
service:
type: NodePort


直接指定值进行更新:

helm install tidb stable/mysql --set persistence.enabled=false

查询 mariadb 历史记录
[root@harbor mysql]# helm history mariadb

回滚操作
[root@harbor mysql]# helm rollback mariadb 1

删除
[root@harbor mysql]# helm history mariadb


[root@harbor templates]# helm ls
NAME NAMESPACE REVISION
mariadb default 1
nginx default 3

查看看渲染过后的形式
helm get manifest nginx

测试执行
helm install --dry-run test ./fengjian/ --debug


helm 模板控制流程
if/else 条件块
with 指定范围
range 循环块

声明和使用命名模版段的操作
define 在模版中声明一个新的命名模版
template 导入一个命名模版
block 声明了一种特殊的可填写的模版区域

apiVersion: v1
kink: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
nacosserver: {{ .Values.nacosserver | default 1.1.1.1 | quote }} #quote 变成加引号
k8s: {{ .Values.source.k8s }}
python: {{ .Values.source.python | repeat 5 | upper }} #repeat重复5次, upper变成大写
{{- if eq .Values.source.python "django" }} # -号删除空行,假如 .Values.source.python 等于python
webport: 80
{{- end }}

helm install --dry-run test ./fengjian/ --debug --set source.python=AI 不会出现webport:80


.Values 表示作用域
apiVersion: v1
kink: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
{{ with .Values }}
nacosserver: {{ .nacosserver | default 1.1.1.1 | quote }} #quote 变成加引号
k8s: {{ .source.k8s }}
python: {{ .source.python | repeat 5 | upper }} #repeat重复5次, upper变成大写
{{- if eq .source.python "django" }} # -号删除空行,假如 .Values.source.python 等于python
webport: 80
{{- end }}
{{- end }}

range 循环
data:
toppings: |-
{{- range .Values.pizzaToppings }}
- {{ . | title | quote }}
{{- end }}

变量
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- $relname := .Release.Name -}}
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
release: {{ $relname }}
{{- end }}


子chart 包
我们只用了一个chart, 但是chart 也可以有子chart的依赖关系, 他们也有自己的值和模版,
1. 子chart 是独立的, 所以子chart不萌明确依赖与其父chart
2. 子chart无法访问其父chart的值
3. 父chart可以覆盖子chart的值
4. helm中有全局值概念, 可以被所有的chart访问。



创建子chart





举报

相关推荐

0 条评论