一、Helm
Helm是Kubernetes 應用的包管理工具,主要用來管理 Charts,類似Linux系統(tǒng)的yum。
Helm Chart 是用來封裝 Kubernetes 原生應用程序的一系列 YAML 文件??梢栽谀悴渴饝玫臅r候自定義應用程序的一些 Metadata,以便于應用程序的分發(fā)。
對于應用發(fā)布者而言,可以通過 Helm 打包應用、管理應用依賴關系、管理應用版本并發(fā)布應用到軟件倉庫。
對于使用者而言,使用 Helm 后不用需要編寫復雜的應用部署文件,可以以簡單的方式在 Kubernetes 上查找、安裝、升級、回滾、卸載應用程序。
二、Helm安裝
安裝包的下載地址:https://github.com/helm/helm/releases,最新版本3.6.2
下載軟件包:helm-v3.6.2-linux-amd64.tar.gz
解壓:
[root@master ~]# tar zxf helm-v3.6.2-linux-amd64.tar.gz
[root@master ~]# cd linux-amd64/
[root@master linux-amd64]# ls
helm LICENSE README.md
[root@master linux-amd64]# cp helm /usr/local/bin/
使命令自動補齊:
[root@master linux-amd64]# echo "source <(helm completion bash)" >> ~/.bashrc
[root@master linux-amd64]# source ~/.bashrc
helm部署完成
[root@master linux-amd64]# helm version
version.BuildInfo{Version:"v3.6.2", GitCommit:"ee407bdf364942bcb8e8c665f82e15aa28009b71", GitTreeState:"clean", GoVersion:"go1.16.5"}
三、Helm倉庫的使用
搜索官方helm hub chart庫
[root@master linux-amd64]# helm search hub redis

Helm 添加第三方 Chart 庫
1、微軟的chart倉庫,基本上官網有的chart這里都有。
http://mirror.azure.cn/kubernetes/charts/
2、阿里的chart倉庫
https://apphub.aliyuncs.com/
3、Kubeapps Hub 官方chart倉庫,國內有點不好使
https://hub.kubeapps.com/charts/incubator
將倉庫添加到helm
[root@master helm]# helm repo add mychart https://apphub.aliyuncs.com/
Error: looks like "https://reg.westos.org/chartrepo/charts" is not a valid chart repository or cannot be reached: Get https://reg.westos.org/chartrepo/charts/index.yaml: x509: certificate signed by unknown authority
報錯原因是缺少證書,可以將證書復制到 redhat 的全局證書地址
[root@master helm]# cd /etc/docker/certs.d/harbor.com/
[root@master harbor.com]# ls
ca.crt
[root@master harbor.com]# cp ca.crt /etc/pki/ca-trust/source/anchors/
[root@master harbor.com]# update-ca-trust #更新證書
創(chuàng)建helm chart
[root@master helm]# helm create mychart
Creating mychart
創(chuàng)建后會在目錄創(chuàng)建一個mychart目錄
[root@master helm]# ls
mychart redis-ha
[root@master helm]# tree mychart/ #查看結構
mychart/
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
其中mychart目錄下的templates目錄中保存有部署的模板文件,values.yaml中定義了部署的變量,Chart.yaml文件包含有version(chart版本)和appVersion(包含應用的版本)
查看并且更改變量文件values.yaml
[root@master mychart]# vim values.yaml
選擇鏡像及標簽和副本數(shù)(這里設置1個)

依賴和模板配置是否正確
[root@master mychart]# helm lint .
==> Linting .
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, no failures
將應用打包
[root@master helm]# ll
total 4
drwxr-xr-x 4 root root 4096 Jul 5 10:45 mychart
[root@master helm]# helm package mychart/
Successfully packaged chart and saved it to: /data/helm/mychart-0.1.0.tgz
# 打包后會在當前目錄下生成一個名為mychart-0.1.0.tgz壓縮包
[root@master helm]# ls
mychart mychart-0.1.0.tgz
其中0.1.0為在Chart.yaml文件中定義的version(chart版本)信息
再次添加
[root@server1 reg.westos.org]# helm repo add mychart https://harbor域名:端口號/chartrepo/charts
"mychart" has been added to your repositories
添加成功,查看倉庫
[root@server1 reg.westos.org]# helm repo list
NAME URL
mychart http://mirror.azure.cn/kubernetes/charts/
添加第三庫之后就可以使用以下方式查詢
[root@master linux-amd64]# helm search repo redis -l
注意:加 -l 選項可以查看歷史版本

刪除第三方庫
[root@master ~]# helm repo remove testdata
"testdata" has been removed from your repositories