官方网站https://helm.sh

helm定位是k8s的包管理工具,Helm 是查找、分享和使用软件构建 Kubernetes 的最优方式。
image.png

安装helm客户端

官方安装教程:https://helm.sh/docs/intro/install/

二进制

github的release地址 https://github.com/helm/helm/releases
根据平台选择下载的版本

image.png

下载发布版本

  1. $wget -b -c https://get.helm.sh/helm-v2.16.6-linux-amd64.tar.gz

解压当前tar文件

  1. $ tar -zxvf helm-v2.16.6-linux-amd64.tar.gz

移动 helm 二进制文件到 系统的bin目录底下

  1. sudo mv linux-amd64/helm /usr/local/bin/helm

查看安装结果

  1. helm version
  2. version.BuildInfo{Version:"v3.4.0", GitCommit:"7090a89efc8a18f3d8178bf47d2462450349a004", GitTreeState:"dirty", GoVersion:"go1.15.3"}

脚本安装

安装helm3

  1. $ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
  2. $ chmod 700 get_helm.sh
  3. $ ./get_helm.sh

或者直接如下所示

  1. curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

MacOS

使用brew info 命令查看helm 版本信息

  1. $ brew info helm
  2. helm: stable 3.4.0 (bottled), HEAD
  3. Kubernetes package manager
  4. https://helm.sh/
  5. /usr/local/Cellar/helm/3.3.0 (56 files, 42.7MB) *
  6. Poured from bottle on 2020-10-01 at 22:27:36
  7. From: https://mirrors.aliyun.com/homebrew/homebrew-core.git/Formula/helm.rb
  8. License: Apache-2.0
  9. ==> Dependencies
  10. Build: go
  11. ==> Options
  12. --HEAD
  13. Install HEAD version
  14. ==> Caveats
  15. Bash completion has been installed to:
  16. /usr/local/etc/bash_completion.d
  17. zsh completions have been installed to:
  18. /usr/local/share/zsh/site-functions

使用brew install 命令安装helm

  1. # brew install helm
  2. ....
  3. ==> Summary
  4. 🍺 /usr/local/Cellar/helm/3.4.0: 57 files, 42.3MB
  5. Removing: /usr/local/Cellar/helm/3.3.0... (56 files, 42.7MB)
  6. # helm version
  7. version.BuildInfo{Version:"v3.4.0", GitCommit:"7090a89efc8a18f3d8178bf47d2462450349a004", GitTreeState:"dirty", GoVersion:"go1.15.3"}

架构

Helm 是包管理工具,Helm 能够:

  1. 从零创建新 chart。
  2. 与存储 chart 的仓库交互, 拉取、保存和更新 chart。
  3. 在 Kubemetes 集群中安装和卸载 release。
  4. 更新、回滚和测试 release。

    chart

    chart 是创建一个应用的信息集合,包括各种 Kubemetes 对象的配直模板、参数定义 、依赖关系、文档说明等。 chart 是应用部署的自包含逻辑单元。可以将chart想象成 apt、yum 中的软件安装包。

    release

    release 是chart的运行实例, 代表了一个正在运行的应用。 当chart被安装到 Kubemetes 集群, 就生成一个 release。chart能次安装到同一个集群,每次安装都是一个release

    Repository

    用于存储和分享打包好的应用(chart)

Helm常用命令

  1. completion 命令补全
  2. create 创建一个给定名称的chart
  3. dependency 管理chart的依赖关系
  4. env helm环境信息
  5. get 获取给定release的扩展信息
  6. help 命令帮助
  7. history 获取release历史
  8. install 部署chart
  9. lint chart进行语法检查
  10. list releases列表,list可简写为ls
  11. package 打包chart
  12. plugin installlistuninstall Helm插件
  13. pull repo中下载chart并(可选)将其解压到本地目录
  14. repo addlistremoveupdateindex Helmrepo
  15. rollback 回滚release到一个以前的版本
  16. search 查询在charts中的关键字
  17. show 显示chart的信息
  18. status 显示给定release的状态
  19. template 本地渲染模板
  20. test 测试运行release
  21. uninstall 删除release
  22. upgrade 升级release
  23. verify 验证给定路径的chart是否已签名且有效
  24. version 显示helm的版本信息

仓库/repo

添加,列出,移除,更新和索引 chart 仓库。可用子命令:add、index、 list、remove、update

  1. Usage:
  2. helm repo [command]
  3. Available Commands:
  4. add add a chart repository
  5. index generate an index file given a directory containing packaged charts
  6. list list chart repositories
  7. remove remove one or more chart repositories
  8. update update information of available charts locally from chart repositories

添加仓库/add

微软仓库

微软仓库 http://mirror.azure.cn/kubernetes/charts/

  1. $ helm repo add stable http://mirror.azure.cn/kubernetes/charts/

bitnami仓库

bitnami仓库 https://charts.bitnami.com/bitnami

官方地址 https://github.com/bitnami/charts

  1. $ helm repo add bitnami https://charts.bitnami.com/bitnami

阿里云仓库

注意:网上很多文章介绍的阿里云: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
早已经不更新无法使用了。
新版本的仓库介绍网址是https://github.com/cloudnativeapp/charts

  1. helm repo add apphub https://apphub.aliyuncs.com

更新仓库/update

  1. $ helm repo update
  2. Hang tight while we grab the latest from your chart repositories...
  3. ...Successfully got an update from the "stable" chart repository
  4. Update Complete. Happy Helming!⎈

查看仓库/list

  1. $ helm repo list
  2. NAME URL
  3. stable http://mirror.azure.cn/kubernetes/charts

删除仓库/remove

  1. $ helm repo remove stable
  2. "stable" has been removed from your repositories

search/搜索

根据关键字搜索 chart。可用子命令:hub、repo

helm search hub

Helm Hub 中搜索 charts,Helm Hub 中公开存放了大量不同版本、公开、可用的 charts。

  1. $ helm search hub wordpress
  2. URL CHART VERSION APP VERSION DESCRIPTION
  3. https://hub.helm.sh/charts/bitnami/wordpress 10.1.5 5.6.0 Web publishing platform for building blogs and ...
  4. https://hub.helm.sh/charts/groundhog2k/wordpress 0.2.3 5.6.0-apache A Helm chart for Wordpress on Kubernetes
  5. https://hub.helm.sh/charts/seccurecodebox/old-w... 2.3.0 4.0 Insecure & Outdated Wordpress Instance: Never e...
  6. https://hub.helm.sh/charts/presslabs/wordpress-... 0.10.5 0.10.5 Presslabs WordPress Operator Helm Chart
  7. https://hub.helm.sh/charts/presslabs/wordpress-... 0.10.3 v0.10.3 A Helm chart for deploying a WordPress site on ...
  8. https://hub.helm.sh/charts/seccurecodebox/wpscan 2.3.0 latest A Helm chart for the WordPress security scanner...
  9. https://hub.helm.sh/charts/presslabs/stack 0.10.3 v0.10.3 Open-Source WordPress Infrastructure on Kubernetes

https://hub.helm.sh 目前重定向到artifacthub,artifacthub可以查找第三方开源的chart,其官方地址:https://artifacthub.io/

图片.png

直接搜索nginx,如下所示
图片.png

helm search repo

helm search repo 从已经添加到本地的仓库列表中搜索 charts。

  1. $helm search repo nginx
  2. NAME CHART VERSION APP VERSION DESCRIPTION
  3. bitnami/nginx 8.2.3 1.19.6 Chart for the nginx server
  4. bitnami/nginx-ingress-controller 7.0.6 0.42.0 Chart for the nginx Ingress controller
  5. helm/nginx-ingress 1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us...
  6. helm/nginx-ldapauth-proxy 0.1.6 1.13.5 DEPRECATED - nginx proxy with ldapauth
  7. helm/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
  8. stable/nginx-ingress 1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us...
  9. stable/nginx-ldapauth-proxy 0.1.6 1.13.5 DEPRECATED - nginx proxy with ldapauth
  10. stable/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
  11. bitnami/kong 3.1.0 2.2.1 Kong is a scalable, open source API layer (aka ...
  12. helm/gcloud-endpoints 0.1.2 1 DEPRECATED Develop, deploy, protect and monitor...
  13. stable/gcloud-endpoints 0.1.2 1 DEPRECATED Develop, deploy, protect and monitor...

install安装

  1. helm install my-db bitnami/mariadb

show

查看 chart 详细信息。可用子命令:all、chart、readme、values
eg:

  1. $helm show chart bitnami/mariadb
  2. annotations:
  3. category: Database
  4. apiVersion: v2
  5. appVersion: 10.5.8
  6. dependencies:
  7. - name: common
  8. repository: https://charts.bitnami.com/bitnami
  9. tags:
  10. - bitnami-common
  11. version: 1.x.x
  12. description: Fast, reliable, scalable, and easy to use open-source relational database
  13. system. MariaDB Server is intended for mission-critical, heavy-load production systems
  14. as well as for embedding into mass-deployed software. Highly available MariaDB cluster.
  15. home: https://github.com/bitnami/charts/tree/master/bitnami/mariadb
  16. icon: https://bitnami.com/assets/stacks/mariadb/img/mariadb-stack-220x234.png
  17. keywords:
  18. - mariadb
  19. - mysql
  20. - database
  21. - sql
  22. - prometheus
  23. maintainers:
  24. - email: containers@bitnami.com
  25. name: Bitnami
  26. name: mariadb
  27. sources:
  28. - https://github.com/bitnami/bitnami-docker-mariadb
  29. - https://github.com/prometheus/mysqld_exporter
  30. - https://mariadb.org
  31. version: 9.1.4

部署之前可以自定义 package 的选项,查询mysql 支持的选项

  1. $ helm show values bitnami/mariadb

status状态

查看上述信息

  1. $ helm status my-db [11:49:15]

查看安装

  1. helm list
  2. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
  3. mysql-1606727896 default 1 2020-11-30 17:18:19.262412 +0800 CST deployed mysql-1.6.9 5.7.30

uninstall卸载

  1. $ helm uninstall mysql-1606727896
  2. release "mysql-1606727896" uninstalled


升级/upgrade

  1. # 升级
  2. helm upgrade --set mysqlRootPassword=passwd db-mysql stable/mysql


回滚/rollback

  1. helm rollback db-mysql 1

template

本地呈现模板

创建/create

创建一个新的 chart

  1. $helm create hello-chart

打包

  1. $helm package hello-chart

helloworld

安装仓库

  1. $helm repo add bitnami https://charts.bitnami.com/bitnami
  2. "bitnami" has been added to your repositories

安装nginx

  1. $helm install my-nginx bitnami/nginx
  2. ....
  3. NGINX can be accessed through the following DNS name from within your cluster:
  4. my-nginx.default.svc.cluster.local (port 80)
  5. To access NGINX from outside the cluster, follow the steps below:
  6. 1. Get the NGINX URL by running these commands:
  7. NOTE: It may take a few minutes for the LoadBalancer IP to be available.
  8. Watch the status with: 'kubectl get svc --namespace default -w my-nginx'
  9. export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-nginx)
  10. export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  11. echo "http://${SERVICE_IP}:${SERVICE_PORT}

查看svc,默认是localhost的端口上

  1. $kubectl get svc
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. my-nginx LoadBalancer 10.96.20.174 localhost 80:32550/TCP 73s

查看list

  1. $helm list
  2. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
  3. my-nginx default 1 2020-12-28 22:48:09.71222 +0800 CST deployed nginx-8.2.3 1.19.6

修改配置参数

  1. $helm upgrade --set metrics.enabled=true my-nginx bitnami/nginx
  2. $helm list
  3. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
  4. my-nginx default 2 2020-12-28 23:07:29.715498 +0800 CST deployed nginx-8.2.3 1.19.6

查看历史版本

  1. $helm history my-nginx
  2. REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
  3. 1 Mon Dec 28 22:48:09 2020 superseded nginx-8.2.3 1.19.6 Install complete
  4. 2 Mon Dec 28 23:07:29 2020 deployed nginx-8.2.3 1.19.6 Upgrade complete

数据回滚

  1. $helm rollback my-nginx 1
  2. Rollback was a success! Happy Helming!
  3. $helm history my-nginx
  4. REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
  5. 1 Mon Dec 28 22:48:09 2020 superseded nginx-8.2.3 1.19.6 Install complete
  6. 2 Mon Dec 28 23:07:29 2020 superseded nginx-8.2.3 1.19.6 Upgrade complete
  7. 3 Mon Dec 28 23:16:37 2020 deployed nginx-8.2.3 1.19.6 Rollback to 1

卸载

  1. $helm uninstall my-nginx
  2. release "my-nginx" uninstalled

阿里云仓库

helm默认路径

  1. By default, the default directories depend on the Operating System. The defaults are listed below:
  2. | Operating System | Cache Path | Configuration Path | Data Path |
  3. |------------------|---------------------------|--------------------------------|-------------------------|
  4. | Linux | $HOME/.cache/helm | $HOME/.config/helm | $HOME/.local/share/helm |
  5. | macOS | $HOME/Library/Caches/helm | $HOME/Library/Preferences/helm | $HOME/Library/helm |
  6. | Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm |

macos数据安装的地址是$HOME/Library/helm
插件安装地址就是$HOME/Library/helm/plugins
helm push 地址就是 $HOME/Library/helm/plugins/helm-push/bin

阿里云仓库地址 https://repomanage.rdc.aliyun.com/my/helm-repos/namespaces
图片.png

参考

https://blog.csdn.net/miss1181248983/article/details/108285276