Introduction
Helm 是 Kubernetes 的包管理工具
Prepare
提前安装好 kubectl 并且配置好 .kube
Install
Commands
Helps
$ helm
The Kubernetes package manager
Common actions for Helm:
- helm search: search for charts
- helm pull: download a chart to your local directory to view
- helm install: upload the chart to Kubernetes
- helm list: list releases of charts
Environment variables:
| Name | Description |
|------------------------------------|-----------------------------------------------------------------------------------|
| $XDG_CACHE_HOME | set an alternative location for storing cached files. |
| $XDG_CONFIG_HOME | set an alternative location for storing Helm configuration. |
| $XDG_DATA_HOME | set an alternative location for storing Helm data. |
| $HELM_DRIVER | set the backend storage driver. Values are: configmap, secret, memory, postgres |
| $HELM_DRIVER_SQL_CONNECTION_STRING | set the connection string the SQL storage driver should use. |
| $HELM_NO_PLUGINS | disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins. |
| $KUBECONFIG | set an alternative Kubernetes configuration file (default "~/.kube/config") |
Helm stores configuration based on the XDG base directory specification, so
- cached files are stored in $XDG_CACHE_HOME/helm
- configuration is stored in $XDG_CONFIG_HOME/helm
- data is stored in $XDG_DATA_HOME/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 |
Usage:
helm [command]
Available Commands:
completion generate autocompletions script for the specified shell (bash or zsh)
create create a new chart with the given name
dependency manage a chart's dependencies
env helm client environment information
get download extended information of a named release
help Help about any command
history fetch release history
install install a chart
lint examine a chart for possible issues
list list releases
package package a chart directory into a chart archive
plugin install, list, or uninstall Helm plugins
pull download a chart from a repository and (optionally) unpack it in local directory
repo add, list, remove, update, and index chart repositories
rollback roll back a release to a previous revision
search search for a keyword in charts
show show information of a chart
status display the status of the named release
template locally render templates
test run tests for a release
uninstall uninstall a release
upgrade upgrade a release
verify verify that a chart at the given path has been signed and is valid
version print the client version information
Flags:
--add-dir-header If true, adds the file directory to the header
--alsologtostderr log to standard error as well as files
--debug enable verbose output
-h, --help help for helm
--kube-apiserver string the address and the port for the Kubernetes API server
--kube-context string name of the kubeconfig context to use
--kube-token string bearer token used for authentication
--kubeconfig string path to the kubeconfig file
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory
--log-file string If non-empty, use this log file
--log-file-max-size uint Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
-n, --namespace string namespace scope for this request
--registry-config string path to the registry config file (default "C:\\Users\\zhangqiang\\AppData\\Roaming\\helm\\registry.json")
--repository-cache string path to the file containing cached repository indexes (default "C:\\Users\\ZHANGQ~1\\AppData\\Local\\Temp\\helm\\repository")
--repository-config string path to the file containing repository names and URLs (default "C:\\Users\\zhangqiang\\AppData\\Roaming\\helm\\repositories.yaml")
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
Use "helm [command] --help" for more information about a command.
Common comands
$ helm version
version.BuildInfo{Version:"v3.2.4", GitCommit:"0ad800ef43d3b826f31a5ad8dfbb4fe05d143688", GitTreeState:"clean", GoVersion:"go1.13.12"}
# Add Official Helm Stable Chart Repo
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
# Add Third-part Helm Chart Repo
$ helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
# Update chart repositories
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "bitnami" chart repository
# Search Helm Chart
$ helm search repo airflow
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/airflow 6.3.5 1.10.10 Apache Airflow is a platform to programmaticall...
stable/airflow 7.2.0 1.10.10 Airflow is a platform to programmatically autho...
# 安装 Helm Chart,自己指定 name: my-airflow,或者 helm install stable/airflow --generate-name 自动生成 name
$ helm install --name-template my-airflow stable/airflow
# 要查看群集上已安装的版本列表
$ helm list
# 卸载已安装的 Helm Chart,可以使用 --keep-history 保留删除记录,然后通过 helm status my-airflow 查看状态
$ helm uninstall my-airflow
# 查看 chart 包可配置参数
$ helm show values my-airflow
# -l, --versions show the long listing, with each version of each chart on its own line,
# for repositories you have added
$ helm search repo -l mysql
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/mysql 8.0.0 8.0.22 Chart to create a Highly available MySQL cluster
...
bitnami/mysql 4.5.2 5.7.26 Chart to create a Highly available MySQL cluster
...
# 获取指定 version 的包
$ helm pull bitnami/mysql --version 4.5.2
更新依赖
# Error: found in Chart.yaml, but missing in charts/ directory: postgresql, redis
$ helm dependency update ./helm/superset
Getting updates for unmanaged Helm repositories...
...Successfully got an update from the "https://kubernetes-charts.storage.googleapis.com/" chart repository
...Successfully got an update from the "https://kubernetes-charts.storage.googleapis.com/" chart repository
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 2 charts
Downloading postgresql from repo https://kubernetes-charts.storage.googleapis.com/
Downloading redis from repo https://kubernetes-charts.storage.googleapis.com/
Deleting outdated charts
修改 Chart
# 获取 chart 压缩包,会将压缩包 airflow-7.2.0.tgz 下载到本地
$ helm pull stable/airflow
$ tar -zxvf airflow-7.2.0.tgz
$ cd airflow && ls -l
total 92
-rw-r--r-- 1 zhangqiang 197121 371 1月 1 1970 Chart.yaml
drwxr-xr-x 1 zhangqiang 197121 0 7月 8 19:56 charts
drwxr-xr-x 1 zhangqiang 197121 0 7月 8 19:56 examples
-rw-r--r-- 1 zhangqiang 197121 96 1月 1 1970 OWNERS
-rw-r--r-- 1 zhangqiang 197121 31708 1月 1 1970 README.md
-rw-r--r-- 1 zhangqiang 197121 332 1月 1 1970 requirements.lock
-rw-r--r-- 1 zhangqiang 197121 269 1月 1 1970 requirements.yaml
drwxr-xr-x 1 zhangqiang 197121 0 7月 8 19:56 templates
-rw-r--r-- 1 zhangqiang 197121 9417 1月 1 1970 UPGRADE.md
# 这里面包含所有可配置的属性
-rw-r--r-- 1 zhangqiang 197121 33948 1月 1 1970 values.yaml
# 修改配置项
$ vim values.yml
# 部署修改后的本地 Chart
$ helm install --name-template my-airflow . --namespace dlink-test
# 或者指定自定义的配置文件
$ helm install --name-template my-airflow -f values.yaml stable/airflow --namespace dlink-test
helm push private registry
debug
# 输出实际执行的 yaml 文件,这对于 debug 很有用
$ helm template test charts/airflow-bitnami-1.10.12 -f charts/airflow-bitnami-1.10.12/values-bjidc-test.yaml
$ helm install --dry-run --debug