Helm3安装和使用
1、Helm简介
Helm 是 Kubernetes 上的包管理器,用来管理 Kubernetes 应用程序,Helm Charts 可帮助您定义,安装和升级
复杂的 Kubernetes 应用程序。Helm 把 Kubernetes 资源(比如deployments、services或ingress等) 打包到一个
chart 中,而 chart 被保存到 chart 仓库。通过 chart 仓库可用来存储和分享 chart。 Helm 使发布可配置,支持
发布应用配置的版本管理,简化了 Kubernetes 部署应用的版本控制、打包、发布、删除、更新等操作。
Helm 之于 Kubernetes 好比 yum 之于 RHEL,或者 apt-get 之于 Ubuntu。Helm 使用 Chart 帮助我们管理应
用,Chart 就好像 RPM 一样,里面描述了应用及其依赖关系。 helm v3 版本了移除 Tiller、让 Helm 成为一个纯
客户端工具。
Helm 可以理解为 Kubernetes 的包管理工具,可以方便地发现、共享和使用为 Kubernetes 构建的应用。
Helm 采用客户端/服务器架构,有如下组件组成:
-
Helm CLI
:是 Helm 客户端,可以在本地执行。 -
Tiller
:是服务器端组件,在 Kubernetes 群集上运行,并管理 Kubernetes 应用程序的生命周期。 -
Repository
:是 Chart 仓库,Helm 客户端通过 HTTP 协议来访问仓库中 Chart 的索引文件和压缩包。
1.1 Helm的三个基本概念
-
Chart
:Helm 应用(package),包括该应用的所有 Kubernetes manifest 模版,类似于 [YUM] RPM 或 Aptdpkg 文件。
-
Repository
:Helm package 存储仓库。 -
Release
:chart 的部署实例,每个 chart 可以部署一个或多个 release。
1.2 Helm工作原理
Helm 把 Kubernetes 资源(比如deployments、services或 ingress等) 打包到一个 chart 中,而 chart 被保存到
chart 仓库。通过 chart 仓库可用来存储和分享 chart。Helm 使发布可配置,支持发布应用配置的版本管理,简
化了 Kubernetes 部署应用的版本控制、打包、发布、删除、更新等操作。
Helm 包括两个部分,helm 客户端和 tiller 服务端。
1.3 Helm客户端
helm 客户端是一个命令行工具,负责管理 charts、reprepository 和release。它通过 gPRC API(使用 kubectl
port-forward 将 tiller 的端口映射到本地,然后再通过映射后的端口跟 tiller 通信)向 tiller 发送请求,并由 tiller 来
管理对应的 Kubernetes 资源。
1.4 tiller服务端
tiller 接收来自 helm 客户端的请求,并把相关资源的操作发送到 Kubernetes,负责管理(安装、查询、升级或删
除等)和跟踪 Kubernetes 资源。为了方便管理,tiller 把 release 的相关信息保存在 kubernetes 的 ConfigMap
中。tiller 对外暴露 gRPC API,供 helm 客户端调用。
1.5 Helm版本选择
helm 和 kubernetes 对应版本:
Helm版本 | 支持的Kubernetes版本 |
---|---|
3.8.x | 1.23.x - 1.20.x |
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 |
1.6 Helm资料
[ helm 官网 ]:https://helm.sh/docs/
[ helm 中文官网 ]:https://helm.sh/zh/docs/
[ Helm GitHub 地址 ]:https://github.com/helm/helm
[ Helm v3.8.0 Documentation ]:https://www.bookstack.cn/books/helm-3.8.0-en
[ Helm 用户与开发者指南 ]:https://whmzsu.github.io/helm-doc-zh-cn/
2、Helm3安装
2.1 二进制安装helm3
[root@master ~]# version=v3.6.0
[root@master ~]# curl -LO https://repo.huaweicloud.com/helm/${version}/helm-${version}-linux-amd64.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 13.5M 100 13.5M 0 0 2636k 0 0:00:05 0:00:05 --:--:-- 2836k
[root@master ~]# tar -zxvf helm-${version}-linux-amd64.tar.gz
linux-amd64/
linux-amd64/helm
linux-amd64/LICENSE
linux-amd64/README.md
[root@master ~]# mv linux-amd64/helm /usr/local/bin/helm && rm -rf linux-amd64
官方下载方式:
$ curl -LO https://get.helm.sh/helm-${version}-linux-amd64.tar.gz
2.2 脚本安装helm
$ curl -L https://git.io/get_helm.sh | bash -s -- -v v3.6.0
另一种方式:
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod +x get_helm.sh
$ ./get_helm.sh
2.3 查看helm版本
[root@master ~]# helm version --short
v3.6.0+g7f2df64
3、Helm组件
Helm 中的重要概念:
-
Helm 命令行工具主要用于 Kubernetes 应用程序 Chart 的创建、打包、发布以及创建和管理本地和远程的
Chart 仓库。
-
chart 是 Helm 的软件包,是创建一个应用的信息集合,采用 TAR 格式,其包含了一组定义 Kubernetes 资源
相关的 YAML 文件,包括各种 Kubernetes 对象的配置模板、参数定义、依赖关系、文档说明等。
-
release 可以理解为 Helm 使用 Chart 包部署的一个应用实例,代表了一个正在运行的应用。当 chart 被安装
到 Kubernetes 集群,就生成一个 release。chart 能够多次安装到同一个集群,每次安装都是一个 release。
-
Repoistory 是 Helm 的软件仓库,Repository 本质上是一个 Web 服务器,该服务器保存了一系列的 Chart
软件包以供用户下载,并且提供了一个该 Repository 的 Chart 包的清单文件以供查询。Helm 可以同时管理
多个不同的 Repository。
4、Helm使用
国内阿里云 chart 仓库:https://github.com/cloudnativeapp/charts
bitnami helm 仓库:https://github.com/bitnami/charts
kube-charts-mirror:https://github.com/BurdenBear/kube-charts-mirror
4.1 添加chart repository
# 阿里云
$ helm repo add ali-stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
# bitnami
$ helm repo add bitnami https://charts.bitnami.com/bitnami
# kube-charts-mirror
$ helm repo add stable https://burdenbear.github.io/kube-charts-mirror
也可以添加官方 chart repository:
$ helm repo add gf-stable https://charts.helm.sh/stable
4.2 查看添加的chart仓库
[root@master ~]# helm repo list
NAME URL
ali-stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
bitnami https://charts.bitnami.com/bitnami
stable https://burdenbear.github.io/kube-charts-mirror
gf-stable https://charts.helm.sh/stable
4.3 更新chart仓库
[root@master ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "ali-stable" chart repository
...Successfully got an update from the "gf-stable" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
4.4 移除chart仓库
[root@master ~]# helm repo remove gf-stable
"gf-stable" has been removed from your repositories
4.5 查看可安装的charts
# 展现仓库的charts
[root@master ~]# helm search repo
NAME CHART VERSION APP VERSION DESCRIPTION
ali-stable/acs-engine-autoscaler 2.1.3 2.1.1 Scales worker nodes within agent pools
ali-stable/aerospike 0.1.7 v3.14.1.2 A Helm chart for Aerospike in Kubernetes
ali-stable/anchore-engine 0.1.3 0.1.6 Anchore container analysis and policy evaluatio...
ali-stable/artifactory 7.0.3 5.8.4 Universal Repository Manager supporting all maj...
ali-stable/artifactory-ha 0.1.0 5.8.4 Universal Repository Manager supporting all maj...
ali-stable/aws-cluster-autoscaler 0.3.2 Scales worker nodes within autoscaling groups.
ali-stable/bitcoind 0.1.0 0.15.1 Bitcoin is an innovative payment network and a ...
ali-stable/buildkite 0.2.1 3 Agent for Buildkite
ali-stable/centrifugo 2.0.0 1.7.3 Centrifugo is a real-time messaging server.
ali-stable/cert-manager 0.2.2 0.2.3 A Helm chart for cert-manager
......
4.6 搜索charts
# helm search repo可以在已添加的存储库中找到chart的名称
# 搜索nginx
[root@master ~]# helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
ali-stable/nginx-ingress 0.9.5 0.10.2 An nginx Ingress controller that uses ConfigMap...
ali-stable/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
bitnami/nginx 15.1.0 1.25.1 NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller 9.7.5 1.8.1 NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel 2.1.15 0.4.9 DEPRECATED NGINX Open Source for Intel is a lig...
gf-stable/nginx-ingress 1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us...
gf-stable/nginx-ldapauth-proxy 0.1.6 1.13.5 DEPRECATED - nginx proxy with ldapauth
gf-stable/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
stable/nginx-ingress 1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us...
stable/nginx-ldapauth-proxy 0.1.5 1.13.5 nginx proxy with ldapauth
stable/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
ali-stable/gcloud-endpoints 0.1.0 Develop, deploy, protect and monitor your APIs ...
gf-stable/gcloud-endpoints 0.1.2 1 DEPRECATED Develop, deploy, protect and monitor...
stable/gcloud-endpoints 0.1.2 1 DEPRECATED Develop, deploy, protect and monitor...
# 搜索mysql
[root@master ~]# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
ali-stable/mysql 0.3.5 Fast, reliable, scalable, and easy to use open-...
bitnami/mysql 9.10.5 8.0.33 MySQL is a fast, reliable, scalable, and easy t...
gf-stable/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
gf-stable/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
gf-stable/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
stable/mysql 1.6.8 5.7.30 Fast, reliable, scalable, and easy to use open-...
stable/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
stable/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
ali-stable/percona 0.3.0 free, fully compatible, enhanced, open source d...
ali-stable/percona-xtradb-cluster 0.0.2 5.7.19 free, fully compatible, enhanced, open source d...
bitnami/phpmyadmin 11.1.3 5.2.1 phpMyAdmin is a free software tool written in P...
gf-stable/percona 1.2.3 5.7.26 DEPRECATED - free, fully compatible, enhanced, ...
gf-stable/percona-xtradb-cluster 1.0.8 5.7.19 DEPRECATED - free, fully compatible, enhanced, ...
gf-stable/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
stable/percona 1.2.2 5.7.26 free, fully compatible, enhanced, open source d...
stable/percona-xtradb-cluster 1.0.7 5.7.19 free, fully compatible, enhanced, open source d...
stable/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
ali-stable/gcloud-sqlproxy 0.2.3 Google Cloud SQL Proxy
ali-stable/mariadb 2.1.6 10.1.31 Fast, reliable, scalable, and easy to use open-...
bitnami/mariadb 12.2.7 10.11.4 MariaDB is an open source, community-developed ...
bitnami/mariadb-galera 8.2.6 10.11.4 MariaDB Galera is a multi-primary database clus...
gf-stable/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
gf-stable/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
stable/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
stable/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
# helm search hub搜索Artifact Hub
# Artifact Hub的地址https://artifacthub.io/
# 其中列出了来自数十个不同存储库的helm chart
# helm search hub向您显示所有可用的charts
[root@master ~]# helm search hub mysql
URL CHART VERSION APP VERSION DESCRIPTION
https://artifacthub.io/packages/helm/bitnami/mysql 9.10.5 8.0.33 MySQL is a fast, reliable, scalable, and easy t...
https://artifacthub.io/packages/helm/kvalitetsi... 9.10.4 8.0.33 MySQL is a fast, reliable, scalable, and easy t...
https://artifacthub.io/packages/helm/saber/mysql 8.8.21 8.0.27 Chart to create a Highly available MySQL cluster
https://artifacthub.io/packages/helm/kubesphere... 1.0.2 5.7.33 High Availability MySQL Cluster, Open Source.
https://artifacthub.io/packages/helm/choerodon/... 8.5.1 8.5.1 Chart to create a Highly available MySQL cluster
https://artifacthub.io/packages/helm/mysql/mysql 2.1.3 8.0.26 deploy mysql standalone or group-replication He...
https://artifacthub.io/packages/helm/stakater/m... 1.0.6 mysql chart that runs on kubernetes
https://artifacthub.io/packages/helm/kubegems/m... 8.9.6 8.0.29 MySQL is a fast, reliable, scalable, and easy t...
https://artifacthub.io/packages/helm/cloudnativ... 5.0.1 8.0.16 Chart to create a Highly available MySQL cluster
......
4.7 展示charts的详细信息
# 展示charts的详细信息
[root@master ~]# helm show all bitnami/nginx
annotations:
category: Infrastructure
licenses: Apache-2.0
apiVersion: v2
appVersion: 1.25.1
dependencies:
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
tags:
- bitnami-common
version: 2.x.x
description: NGINX Open Source is a web server that can be also used as a reverse
proxy, load balancer, and HTTP cache. Recommended for high-demanding sites due to
its ability to provide faster content.
home: https://bitnami.com
icon: https://bitnami.com/assets/stacks/nginx/img/nginx-stack-220x234.png
keywords:
- nginx
- http
- web
- www
- reverse proxy
maintainers:
- name: VMware, Inc.
url: https://github.com/bitnami/charts
name: nginx
sources:
- https://github.com/bitnami/charts/tree/main/bitnami/nginx
version: 15.1.0
......
4.8 查看charts上可配置的选项
# 要查看charts上可配置的选项,请使用helm show values
[root@master ~]# helm show values bitnami/nginx
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0
## @section Global parameters
## Global Docker image parameters
## Please, note that this will override the image parameters, including dependencies, configured to use the global value
## Current available global Docker image parameters: imageRegistry, imagePullSecrets and storageClass
## @param global.imageRegistry Global Docker image registry
## @param global.imagePullSecrets Global Docker registry secret names as an array
##
global:
imageRegistry: ""
## E.g.
## imagePullSecrets:
## - myRegistryKeySecretName
##
imagePullSecrets: []
## @section Common parameters
## @param nameOverride String to partially override nginx.fullname template (will maintain the release name)
##
nameOverride: ""
## @param fullnameOverride String to fully override nginx.fullname template
##
fullnameOverride: ""
## @param namespaceOverride String to fully override common.names.namespace
##
namespaceOverride: ""
## @param kubeVersion Force target Kubernetes version (using Helm capabilities if not set)
##
kubeVersion: ""
## @param clusterDomain Kubernetes Cluster Domain
##
clusterDomain: cluster.local
## @param extraDeploy Extra objects to deploy (value evaluated as a template)
##
extraDeploy: []
## @param commonLabels Add labels to all the deployed resources
##
commonLabels: {}
## @param commonAnnotations Add annotations to all the deployed resources
##
commonAnnotations: {}
......
4.9 安装charts
# 安装
# 在最简单的情况下,它需要两个参数:您选择的版本名称和您要安装的charts的名称
# helm install happy-panda bitnami/wordpress
# 如果您希望Helm为您生成名称,请省略发布名称并使用--generate-name
# helm install --generate-name bitnami/wordpress
# 更多安装方式
# 1、一个charts存储库(正如我们在上面看到的)
# 2、本地charts存档(helm install foo foo-0.1.1.tgz)
# 3、解压后的charts目录(helm install foo path/to/foo)
# 4、完整网址(helm install foo https://example.com/charts/foo-1.2.3.tgz)
# 安装bitnami/wordpress: helm install --generate-name bitnami/wordpress
# 下面部署nginx应用,直接覆盖参数部署为NodePort类型
[root@master ~]# helm install my-nginx-app --set service.type=NodePort bitnami/nginx
NAME: my-nginx-app
LAST DEPLOYED: Tue Jul 11 20:41:00 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 15.1.0
APP VERSION: 1.25.1
** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:
my-nginx-app.default.svc.cluster.local (port 80)
To access NGINX from outside the cluster, follow the steps below:
1. Get the NGINX URL by running these commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services my-nginx-app)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
4.10 查看安装列表
# 查看安装列表
# helm ls
# 或者
# helm list
[root@master ~]# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-nginx-app default 1 2023-07-11 20:41:00.409971233 +0800 CST deployed nginx-15.1.0 1.25.1
4.11 查看状态
# 查看状态
[root@master ~]# helm status my-nginx-app
NAME: my-nginx-app
LAST DEPLOYED: Tue Jul 11 20:41:00 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 15.1.0
APP VERSION: 1.25.1
** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:
my-nginx-app.default.svc.cluster.local (port 80)
To access NGINX from outside the cluster, follow the steps below:
1. Get the NGINX URL by running these commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services my-nginx-app)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo "http://${NODE_IP}:${NODE_PORT}"
# 当然我们也可以通过kubectl命令查看相关的pod是否创建成功
[root@master ~]# kubectl get svc,pod -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 24h <none>
service/my-nginx-app NodePort 10.100.84.209 <none> 80:30585/TCP 4m36s app.kubernetes.io/instance=my-nginx-app,app.kubernetes.io/name=nginx
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/my-nginx-app-5f4f995dfd-wk49k 1/1 Running 0 4m36s 10.244.140.85 slave2 <none> <none>
# 浏览器访问
# http://<node-ip>:ndoeport
[root@master ~]# curl 192.168.226.200:30585
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
4.12 卸载
# 卸载
[root@master ~]# helm uninstall my-nginx-app
release "my-nginx-app" uninstalled