官方网站https://helm.sh
helm定位是k8s的包管理工具,Helm 是查找、分享和使用软件构建 Kubernetes 的最优方式。
安装helm客户端
官方安装教程:https://helm.sh/docs/intro/install/
二进制
github的release地址 https://github.com/helm/helm/releases
根据平台选择下载的版本
下载发布版本
$wget -b -c https://get.helm.sh/helm-v2.16.6-linux-amd64.tar.gz
解压当前tar文件
$ tar -zxvf helm-v2.16.6-linux-amd64.tar.gz
移动 helm 二进制文件到 系统的bin目录底下
sudo mv linux-amd64/helm /usr/local/bin/helm
查看安装结果
helm version
version.BuildInfo{Version:"v3.4.0", GitCommit:"7090a89efc8a18f3d8178bf47d2462450349a004", GitTreeState:"dirty", GoVersion:"go1.15.3"}
脚本安装
安装helm3
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh
或者直接如下所示
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
MacOS
使用brew info 命令查看helm 版本信息
$ brew info helm
helm: stable 3.4.0 (bottled), HEAD
Kubernetes package manager
https://helm.sh/
/usr/local/Cellar/helm/3.3.0 (56 files, 42.7MB) *
Poured from bottle on 2020-10-01 at 22:27:36
From: https://mirrors.aliyun.com/homebrew/homebrew-core.git/Formula/helm.rb
License: Apache-2.0
==> Dependencies
Build: go ✘
==> Options
--HEAD
Install HEAD version
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completions have been installed to:
/usr/local/share/zsh/site-functions
使用brew install 命令安装helm
# brew install helm
....
==> Summary
🍺 /usr/local/Cellar/helm/3.4.0: 57 files, 42.3MB
Removing: /usr/local/Cellar/helm/3.3.0... (56 files, 42.7MB)
# helm version
version.BuildInfo{Version:"v3.4.0", GitCommit:"7090a89efc8a18f3d8178bf47d2462450349a004", GitTreeState:"dirty", GoVersion:"go1.15.3"}
架构
Helm 是包管理工具,Helm 能够:
- 从零创建新 chart。
- 与存储 chart 的仓库交互, 拉取、保存和更新 chart。
- 在 Kubemetes 集群中安装和卸载 release。
- 更新、回滚和测试 release。
chart
chart 是创建一个应用的信息集合,包括各种 Kubemetes 对象的配直模板、参数定义 、依赖关系、文档说明等。 chart 是应用部署的自包含逻辑单元。可以将chart想象成 apt、yum 中的软件安装包。release
release 是chart的运行实例, 代表了一个正在运行的应用。 当chart被安装到 Kubemetes 集群, 就生成一个 release。chart能次安装到同一个集群,每次安装都是一个releaseRepository
用于存储和分享打包好的应用(chart)
Helm常用命令
completion 命令补全
create 创建一个给定名称的chart
dependency 管理chart的依赖关系
env helm环境信息
get 获取给定release的扩展信息
help 命令帮助
history 获取release历史
install 部署chart
lint 对chart进行语法检查
list releases列表,list可简写为ls
package 打包chart
plugin install、list、uninstall Helm插件
pull 从repo中下载chart并(可选)将其解压到本地目录
repo add、list、remove、update、index Helm的repo
rollback 回滚release到一个以前的版本
search 查询在charts中的关键字
show 显示chart的信息
status 显示给定release的状态
template 本地渲染模板
test 测试运行release
uninstall 删除release
upgrade 升级release
verify 验证给定路径的chart是否已签名且有效
version 显示helm的版本信息
仓库/repo
添加,列出,移除,更新和索引 chart 仓库。可用子命令:add、index、 list、remove、update
Usage:
helm repo [command]
Available Commands:
add add a chart repository
index generate an index file given a directory containing packaged charts
list list chart repositories
remove remove one or more chart repositories
update update information of available charts locally from chart repositories
添加仓库/add
微软仓库
微软仓库 http://mirror.azure.cn/kubernetes/charts/
$ helm repo add stable http://mirror.azure.cn/kubernetes/charts/
bitnami仓库
bitnami仓库 https://charts.bitnami.com/bitnami
官方地址 https://github.com/bitnami/charts
$ helm repo add bitnami https://charts.bitnami.com/bitnami
阿里云仓库
注意:网上很多文章介绍的阿里云: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
早已经不更新无法使用了。
新版本的仓库介绍网址是https://github.com/cloudnativeapp/charts
helm repo add apphub https://apphub.aliyuncs.com
更新仓库/update
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
查看仓库/list
$ helm repo list
NAME URL
stable http://mirror.azure.cn/kubernetes/charts
删除仓库/remove
$ helm repo remove stable
"stable" has been removed from your repositories
search/搜索
helm search hub
从 Helm Hub 中搜索 charts,Helm Hub 中公开存放了大量不同版本、公开、可用的 charts。
$ helm search hub wordpress
URL CHART VERSION APP VERSION DESCRIPTION
https://hub.helm.sh/charts/bitnami/wordpress 10.1.5 5.6.0 Web publishing platform for building blogs and ...
https://hub.helm.sh/charts/groundhog2k/wordpress 0.2.3 5.6.0-apache A Helm chart for Wordpress on Kubernetes
https://hub.helm.sh/charts/seccurecodebox/old-w... 2.3.0 4.0 Insecure & Outdated Wordpress Instance: Never e...
https://hub.helm.sh/charts/presslabs/wordpress-... 0.10.5 0.10.5 Presslabs WordPress Operator Helm Chart
https://hub.helm.sh/charts/presslabs/wordpress-... 0.10.3 v0.10.3 A Helm chart for deploying a WordPress site on ...
https://hub.helm.sh/charts/seccurecodebox/wpscan 2.3.0 latest A Helm chart for the WordPress security scanner...
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/
直接搜索nginx,如下所示
helm search repo
helm search repo 从已经添加到本地的仓库列表中搜索 charts。
$helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/nginx 8.2.3 1.19.6 Chart for the nginx server
bitnami/nginx-ingress-controller 7.0.6 0.42.0 Chart for the nginx Ingress controller
helm/nginx-ingress 1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us...
helm/nginx-ldapauth-proxy 0.1.6 1.13.5 DEPRECATED - nginx proxy with ldapauth
helm/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.6 1.13.5 DEPRECATED - nginx proxy with ldapauth
stable/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
bitnami/kong 3.1.0 2.2.1 Kong is a scalable, open source API layer (aka ...
helm/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...
install安装
helm install my-db bitnami/mariadb
show
查看 chart 详细信息。可用子命令:all、chart、readme、values
eg:
$helm show chart bitnami/mariadb
annotations:
category: Database
apiVersion: v2
appVersion: 10.5.8
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
tags:
- bitnami-common
version: 1.x.x
description: Fast, reliable, scalable, and easy to use open-source relational database
system. MariaDB Server is intended for mission-critical, heavy-load production systems
as well as for embedding into mass-deployed software. Highly available MariaDB cluster.
home: https://github.com/bitnami/charts/tree/master/bitnami/mariadb
icon: https://bitnami.com/assets/stacks/mariadb/img/mariadb-stack-220x234.png
keywords:
- mariadb
- mysql
- database
- sql
- prometheus
maintainers:
- email: containers@bitnami.com
name: Bitnami
name: mariadb
sources:
- https://github.com/bitnami/bitnami-docker-mariadb
- https://github.com/prometheus/mysqld_exporter
- https://mariadb.org
version: 9.1.4
部署之前可以自定义 package 的选项,查询mysql 支持的选项
$ helm show values bitnami/mariadb
status状态
查看上述信息
$ helm status my-db [11:49:15]
查看安装
helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1606727896 default 1 2020-11-30 17:18:19.262412 +0800 CST deployed mysql-1.6.9 5.7.30
uninstall卸载
$ helm uninstall mysql-1606727896
release "mysql-1606727896" uninstalled
升级/upgrade
# 升级
helm upgrade --set mysqlRootPassword=passwd db-mysql stable/mysql
回滚/rollback
helm rollback db-mysql 1
template
本地呈现模板
创建/create
创建一个新的 chart
$helm create hello-chart
打包
$helm package hello-chart
helloworld
安装仓库
$helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
安装nginx
$helm install my-nginx bitnami/nginx
....
NGINX can be accessed through the following DNS name from within your cluster:
my-nginx.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:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
Watch the status with: 'kubectl get svc --namespace default -w my-nginx'
export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-nginx)
export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "http://${SERVICE_IP}:${SERVICE_PORT}
查看svc,默认是localhost的端口上
$kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx LoadBalancer 10.96.20.174 localhost 80:32550/TCP 73s
查看list
$helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-nginx default 1 2020-12-28 22:48:09.71222 +0800 CST deployed nginx-8.2.3 1.19.6
修改配置参数
$helm upgrade --set metrics.enabled=true my-nginx bitnami/nginx
$helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-nginx default 2 2020-12-28 23:07:29.715498 +0800 CST deployed nginx-8.2.3 1.19.6
查看历史版本
$helm history my-nginx
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon Dec 28 22:48:09 2020 superseded nginx-8.2.3 1.19.6 Install complete
2 Mon Dec 28 23:07:29 2020 deployed nginx-8.2.3 1.19.6 Upgrade complete
数据回滚
$helm rollback my-nginx 1
Rollback was a success! Happy Helming!
$helm history my-nginx
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon Dec 28 22:48:09 2020 superseded nginx-8.2.3 1.19.6 Install complete
2 Mon Dec 28 23:07:29 2020 superseded nginx-8.2.3 1.19.6 Upgrade complete
3 Mon Dec 28 23:16:37 2020 deployed nginx-8.2.3 1.19.6 Rollback to 1
卸载
$helm uninstall my-nginx
release "my-nginx" uninstalled
阿里云仓库
helm默认路径
By default, the default directories depend on the Operating System. The defaults are listed below:
| Operating System | Cache Path | Configuration Path | Data Path |
|------------------|---------------------------|--------------------------------|-------------------------|
| Linux | $HOME/.cache/helm | $HOME/.config/helm | $HOME/.local/share/helm |
| macOS | $HOME/Library/Caches/helm | $HOME/Library/Preferences/helm | $HOME/Library/helm |
| 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
参考
https://blog.csdn.net/miss1181248983/article/details/108285276