Helm入门(一)

Helm是Kubernetes的包管理工具,如果比作操作系统,那么Helm就好比yum,apt-get,homebrew。使用Helm chart可以方便我们部署和管理自己的应用。
Helm 安装 charts 到 Kubernetes 集群中,每次安装都会创建一个新的 release。

环境准备:

  • 一个 Kubernetes 集群
  • 安装和配置Helm
Helm和对应支持的Kubernetes版本
Helm 版本 支持的 Kubernetes 版本
3.7.x 1.22.x - 1.19.x
3.6.x 1.21.x - 1.18.x
3.5.x 1.20.x - 1.17.x
3.4.x 1.19.x - 1.16.x
3.3.x 1.18.x - 1.15.x
3.2.x 1.18.x - 1.15.x
3.1.x 1.17.x - 1.14.x
3.0.x 1.16.x - 1.13.x
2.16.x 1.16.x - 1.15.x
2.15.x 1.15.x - 1.14.x
2.14.x 1.14.x - 1.13.x
2.13.x 1.13.x - 1.12.x
2.12.x 1.12.x - 1.11.x
2.11.x 1.11.x - 1.10.x
2.10.x 1.10.x - 1.9.x
2.9.x 1.10.x - 1.9.x
2.8.x 1.9.x - 1.8.x
2.7.x 1.8.x - 1.7.x
2.6.x 1.7.x - 1.6.x
2.5.x 1.6.x - 1.5.x
2.4.x 1.6.x - 1.5.x
2.3.x 1.5.x - 1.4.x
2.2.x 1.5.x - 1.4.x
2.1.x 1.5.x - 1.4.x
2.0.x 1.4.x - 1.3.x

安装Helm

二进制版本安装::
1、 下载 需要的版本
2、解压,并移动到/usr/local/bin/目录

tar -zxvf helm-v3.2.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm

3、输入helm version查看安装结果

[root@localhost ~]# helm version
version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}

初始化

添加一个chart仓库

[root@localhost ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
[root@localhost ~]#
[root@localhost ~]# helm repo list
NAME            URL
sonarqube       https://SonarSource.github.io/helm-chart-sonarqube
bitnami         https://charts.bitnami.com/bitnami
[root@localhost ~]#

添加仓库完成后,可以看到可以安装的charts列表

[root@localhost ~]# helm search repo bitnami
NAME                                            CHART VERSION   APP VERSION     DESCRIPTION
bitnami/bitnami-common                          0.0.9           0.0.9           DEPRECATED Chart with custom templates used in ...
bitnami/airflow                                 11.1.13         2.2.3           Apache Airflow is a platform to programmaticall...
bitnami/apache                                  8.11.1          2.4.52          Chart for Apache HTTP Server
bitnami/argo-cd                                 2.0.19          2.2.1           Declarative, GitOps continuous delivery tool fo...
bitnami/argo-workflows                          0.1.13          3.2.6           Argo Workflows is meant to orchestrate Kubernet...
bitnami/aspnet-core                             2.0.3           3.1.22          ASP.NET Core is an open-source framework create...
bitnami/cassandra                               9.0.10          4.0.1           Apache Cassandra is a free and open-source dist...
bitnami/cert-manager                            0.1.29          1.6.1           Cert Manager is a Kubernetes add-on to automate...
bitnami/common                                  1.10.3          1.10.0          A Library Helm Chart for grouping common logic ...
bitnami/concourse                               0.1.17          7.6.0           Concourse is a pipeline-based continuous thing-...
bitnami/consul                                  10.1.8          1.11.1          Highly available and distributed service discov...

安装chart

通过helm install命令安装官方的bitnami charts。每当执行 helm install的时候,都会创建一个新的发布版本。 所以一个chart在同一个集群里面可以被安装多次,每一个都可以被独立的管理和升级。

[root@localhost ~]# helm repo update      #从chart仓库获取最新的charts列表
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "sonarqube" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈ Happy Helming!⎈
[root@localhost ~]#
[root@localhost ~]# helm install bitnami/mysql --generate-name
NAME: mysql-1640865343
LAST DEPLOYED: Thu Dec 30 19:55:45 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 8.8.18
APP VERSION: 8.0.27
······

Helm按照以下顺序安装资源:
Namespace
NetworkPolicy
ResourceQuota
LimitRange
PodSecurityPolicy
PodDisruptionBudget
ServiceAccount
Secret
SecretList
ConfigMap
StorageClass
PersistentVolume
PersistentVolumeClaim
CustomResourceDefinition
ClusterRole
ClusterRoleList
ClusterRoleBinding
ClusterRoleBindingList
Role
RoleList
RoleBinding
RoleBindingList
Service
DaemonSet
Pod
ReplicationController
ReplicaSet
Deployment
HorizontalPodAutoscaler
StatefulSet
Job
CronJob
Ingress
APIService

安装完成后,可以通过执行 helm show chart bitnami/mysql命令简单的了解到这个chart的基本信息。 也可以执行 helm show all bitnami/mysql获取关于该chart的所有信息。
使用helm list (或 helm ls) 命令列出所有被部署的版本。

[root@localhost ~]# helm list
NAME                    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
mysql-1640865343        default         1               2021-12-30 19:55:45.743915295 +0800 CST deployed        mysql-8.8.18    8.0.27
mysql-1640865721        default         1               2021-12-30 20:02:04.3998849 +0800 CST   deployed        mysql-8.8.18    8.0.27

卸载版本

使用helm uninstall命令卸载版本,该命令会从Kubernetes卸载 mysql-1640865721, 它将删除和该版本相关的所有相关资源(service、deployment、 pod等等)甚至版本历史。
如果在执行helm uninstall的时候提供--keep-history 选项, Helm将会保存版本历史。 可以通过命令helm status查看该版本的信息。

[root@localhost ~]# helm uninstall mysql-1640865721
release "mysql-1640865721" uninstalled
[root@localhost ~]# helm status mysql-1640865721
Error: release: not found
[root@localhost ~]#
[root@localhost ~]# helm uninstall mysql-1640865343 --keep-history
release "mysql-1640865343" uninstalled
[root@localhost ~]# helm status mysql-1640865343
NAME: mysql-1640865343
LAST DEPLOYED: Thu Dec 30 19:55:45 2021
NAMESPACE: default
STATUS: uninstalled
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 8.8.18
APP VERSION: 8.0.27
······

查看帮助信息

使用helm help命令,或者在任意命令后添加-h选项:helm list -h

你可能感兴趣的:(Helm入门(一))