Helm v3概念和常用命令详述

Helm v3概念

  • Chart

Helm的应用包,采用tgz格式。类似于Yum的RPM包,其包含了一组定义Kubernetes资源相关的YAML文件。也称为应用Chart。

  • Repoistory

Helm的应用仓库,Repository本质上是一个Web服务器,该服务器保存了一系列的Chart应用包以供用户下载,并且提供了一个该Repository的Chart包的清单文件以供查询。Helm可以同时管理多个不同的Repository。

Helm社区官方提供了stable和incubator仓库,但Helm社区没有打算独占仓库,而是允许其他人和组织也可以搭建仓库。仓库可以是公共仓库,也可以是私有仓库。

  • Hub

不同的个人和组织提供的公共仓库形成了分散和分布的Helm仓库,不利于查找,所以官方提供了Helm Hub,各公共仓库可以注册到Helm Hub中以方便集中查找,Helm Hub只是分布的仓库的集中展示中心。

仓库注册到Helm Hub时,会将Chart清单文件向Helm Hub同步一份,这样可以在Helm Hub集中展示仓库列表和各仓库中的Chart列表。

Helm Hub地址为https://hub.helm.sh/charts,下图的左边为注册到Helm Hub中的仓库列表,点击仓库链接,右边为该仓库的Chart列表。
Helm Hub
Chart包也就是tgz文件实际上存储在各仓库中。Helm Hub并不实际存储Chart包。Helm只是在查询Chart时和Helm Hub有交互,其它操作都是和仓库直接交互的。

点击上图的某个Chart图标,打开Chart详细说明页面(下图),右边Install区域可以看到如何增加该Chart所在的仓库。
Helm Hub Chart

  • Release

在Kubernetes集群上运行的Chart的一个实例。在同一个集群上,一个Chart可以安装很多次。每次安装都会创建一个新的Release。例如一个MySQL Chart,如果想在服务器上运行两个MySQL数据库,就可以把这个Chart安装两次。每次安装都会生成一个新的Release。


Helm v3常用命令

索引

  • helm version

查看helm版本。

helm version
version.BuildInfo{Version:"v3.0.2", GitCommit:"19e47ee3283ae98139d98460de796c1be1e3975f", GitTreeState:"clean", GoVersion:"go1.13.5"}

查看helm短版本。

helm version --short
v3.0.2+g19e47ee

  • helm help

查看命令行帮助,有以下几种方式:

  • helm
  • helm help
  • helm help [command]
  • helm -h(常用)
  • helm --help
  • helm [command] -h(常用)
  • helm [command] -help
  • helm [command] [sub command] -h(常用)
  • helm [command] [sub command] -help

查看命令行帮助。

helm -h
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       |
| $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        examines 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      displays 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-context string              name of the kubeconfig context to use
      --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 "/root/.config/helm/registry.json")
      --repository-cache string          path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
      --repository-config string         path to the file containing repository names and URLs (default "/root/.config/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.

  • helm completion

Helm命令补全。

yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
source <(helm completion bash)

# 顺便补全kubectl。
source <(kubectl completion bash)

helm <tab>
completion  dependency  get         install     list        plugin      repo        search      status      test        upgrade     version
create      env         history     lint        package     pull        rollback    show        template    uninstall   verify

  • helm env

打印出Helm使用的所有环境变量。

helm env
HELM_KUBECONTEXT=""
HELM_BIN="helm"
HELM_DEBUG="false"
HELM_PLUGINS="/root/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"
HELM_NAMESPACE="default"

  • helm repo

Helm仓库的管理。

  • helm repo add

增加仓库,以下命令为增加helm官方stable仓库,命令中stable为仓库名称,链接为仓库的Chart清单文件地址。当增加仓库时,Helm会将仓库的Chart清单文件下载到本地并存放到Kubernetes中,以后helm search、install和pull等操作都通过仓库名称到Kubernetes中查找该仓库相关的Chart包。可以注意到官方的stable仓库的地址和Helm Hub地址是不同的,两者是独立存在的,stable仓库只是众多公共仓库之一,但是是Helm官方提供的。

helm repo add stable https://kubernetes-charts.storage.googleapis.com

以下为官方stable仓库的清单文件,地址https://kubernetes-charts.storage.googleapis.com。可以看出就是一个个Chart包的信息,按照字母顺序排列,而且只到D开头的Chart包,所有Chart清单应该分片为多个清单文件,应该多次请求才能全部下载下来。也可以直接访问https://kubernetes-charts.storage.googleapis.com/ambassador-5.3.1.tgz将tgz包下载下来。

<ListBucketResult xmlns="http://doc.s3.amazonaws.com/2006-03-01">
  <Name>kubernetes-charts</Name>
  <Prefix/>
  <Marker/>
  <NextMarker>datadog-0.2.0.tgz</NextMarker>
  <IsTruncated>true</IsTruncated>
  <Contents>
    <Key>acs-engine-autoscaler-0.1.0.tgz</Key>
    <Generation>1501637633913843</Generation>
    <MetaGeneration>1</MetaGeneration>
    <LastModified>2017-08-02T01:33:53.600Z</LastModified>
    <ETag>"7ba1dd9555e78f23eac07a7223cdad18"</ETag>
    <Size>4069</Size>
  </Contents>
  <Contents>
    <Key>acs-engine-autoscaler-1.0.0.tgz</Key>
    <Generation>1505061247273212</Generation>
    <MetaGeneration>1</MetaGeneration>
    <LastModified>2017-09-10T16:34:07.187Z</LastModified>
    <ETag>"fcea91b52795fb8576be7a62ceebb731"</ETag>
    <Size>4229</Size>
  </Contents>
  <Contents>
    <Key>acs-engine-autoscaler-2.0.0.tgz</Key>
    <Generation>1507577650862706</Generation>
    <MetaGeneration>1</MetaGeneration>
    <LastModified>2017-10-09T19:34:10.842Z</LastModified>
    <ETag>"500fa8390acdd0cc98eb8d0548ec8268"</ETag>
    <Size>4238</Size>
  </Contents>
  <Contents>
    <Key>acs-engine-autoscaler-2.1.0.tgz</Key>
    <Generation>1510935533778152</Generation>
    <MetaGeneration>1</MetaGeneration>
    <LastModified>2017-11-17T16:18:53.738Z</LastModified>
    <ETag>"d9f92504ce7cee39d5790e56c14bc8f0"</ETag>
    <Size>4228</Size>
  </Contents>
  .....
  <Contents>
    <Key>datadog-0.2.0.tgz</Key>
    <Generation>1486783107723000</Generation>
    <MetaGeneration>1</MetaGeneration>
    <LastModified>2017-02-11T03:18:27.708Z</LastModified>
    <ETag>"066d6eb53b0c70318322b87d980753ae"</ETag>
    <Size>2968</Size>
  </Contents>
</ListBucketResult>

以下为几个常用的仓库的添加命令。

helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add aliyuncs https://apphub.aliyuncs.com
helm repo add kong https://charts.konghq.com
  • helm repo list

查看加到本地的仓库列表。

helm repo list
NAME            URL
stable          https://kubernetes-charts.storage.googleapis.com
aliyuncs        https://apphub.aliyuncs.com
bitnami         https://charts.bitnami.com/bitnami
incubator       https://kubernetes-charts-incubator.storage.googleapis.com
kong            https://charts.konghq.com

Helm v3取消了v2的local repo,Helm v3本地增加的仓库列表存放在/root/.config/helm/repositories.yaml

cat /root/.config/helm/repositories.yaml
apiVersion: ""
generated: "0001-01-01T00:00:00Z"
repositories:
- caFile: ""
  certFile: ""
  keyFile: ""
  name: stable
  password: ""
  url: https://kubernetes-charts.storage.googleapis.com
  username: ""
- caFile: ""
  certFile: ""
  keyFile: ""
  name: aliyuncs
  password: ""
  url: https://apphub.aliyuncs.com
  username: ""
- caFile: ""
  certFile: ""
  keyFile: ""
  name: bitnami
  password: ""
  url: https://charts.bitnami.com/bitnami
  username: ""
- caFile: ""
  certFile: ""
  keyFile: ""
  name: incubator
  password: ""
  url: https://kubernetes-charts-incubator.storage.googleapis.com
  username: ""
- caFile: ""
  certFile: ""
  keyFile: ""
  name: kong
  password: ""
  url: https://charts.konghq.com
  username: ""

仓库的Chart清单应该是存储在Kubernetes的etcd中,但在/root/.cache/helm/repository存储了备份。下载的Chart包也缓存在该目录下。

ls /root/.cache/helm/repository
aliyuncs-index.yaml   bitnami-index.yaml    kong-index.yaml  nginx-5.1.4.tgz    tomcat-6.1.3.tgz
ambassador-6.1.1.tgz  incubator-index.yaml  mysql-1.6.2.tgz  stable-index.yaml
  • helm repo remove

移除本地仓库。

helm repo remove kong
"kong" has been removed from your repositories
  • helm repo update

更新本地仓库,将仓库的实时清单文件更新到Kubernetes中。

helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "kong" chart repository
...Successfully got an update from the "incubator" chart repository
...Successfully got an update from the "aliyuncs" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
  • helm repo index

根据本地目录生成Chart清单文件。和helm package命令配合用来搭建私有仓库。

ls
kong-1.1.1.tgz  tomcat-6.1.6.tgz

helm repo index .

ls
index.yaml  kong-1.1.1.tgz  tomcat-6.1.6.tgz

cat index.yaml
apiVersion: v1
entries:
  kong:
  - apiVersion: v1
    appVersion: "1.4"
    created: "2020-02-12T10:04:06.478170989+08:00"
    dependencies:
    - condition: postgresql.enabled
      name: postgresql
      repository: https://kubernetes-charts.storage.googleapis.com/
      version: ~8.1.0
    description: The Cloud-Native Ingress and API-management
    digest: 2439910d3de8757b2c7ed8c57952537df2c15e755df9ec35675bb26a81b7b1c2
    home: https://konghq.com/
    icon: https://s3.amazonaws.com/downloads.kong/universe/assets/icon-kong-inc-large.png
    maintainers:
    - email: shashi@konghq.com
      name: shashiranjan84
    - email: harry@konghq.com
      name: hbagdi
    name: kong
    urls:
    - kong-1.1.1.tgz
    version: 1.1.1
  tomcat:
  - apiVersion: v1
    appVersion: 9.0.30
    created: "2020-02-12T10:04:06.489744806+08:00"
    description: Chart for Apache Tomcat
    digest: 2b2e7d7ba14b1e8a7ed9ef42fa7d9591fe5e9514224728188056ba5b2bba79f2
    home: http://tomcat.apache.org
    icon: https://bitnami.com/assets/stacks/tomcat/img/tomcat-stack-110x117.png
    keywords:
    - tomcat
    - java
    - http
    - web
    - application server
    - jsp
    maintainers:
    - email: containers@bitnami.com
      name: Bitnami
    name: tomcat
    sources:
    - https://github.com/bitnami/bitnami-docker-tomcat
    urls:
    - tomcat-6.1.6.tgz
    version: 6.1.6
generated: "2020-02-12T10:04:06.40968204+08:00"

生成index.yaml后,将所有的tgz的Chart包和index.yaml放到web服务器提供下载,即可搭建一个私有仓库。

  • helm search

查询Chart包,查询命令分为helm search hub和helm search repo。

  • helm search hub,只从Helm Hub中查找Chart,这些Chart来自于注册到Helm Hub中的各个仓库。

  • helm search repo,从所有加到本地的仓库中查找应用,这些仓库加到本地时Chart清单文件已被存放到Kubernetes中,所以查找应用时无需联网。

  • helm search hub

从Helm Hub中查询Chart,而且只展示最新Chart版本。

helm search hub kong
URL                                     CHART VERSION   APP VERSION     DESCRIPTION
https://hub.helm.sh/charts/stable/kong  0.36.6          1.4             DEPRECATED The Cloud-Native Ingress and API-man...
https://hub.helm.sh/charts/kong/kong    1.1.1           1.4             The Cloud-Native Ingress and API-management

注意到Kong在Helm Hub中有两条记录,应该是原来Kong公司没有自己的仓库,Kong Chart是直接存放在官方的stab

  • 11
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Helm是一个用于管理Kubernetes应用程序的工具,它可以帮助开发者更轻松地部署、升级和管理应用程序的版本。Helm v2和v3是Helm的两个主要版本,它们之间有一些重要的区别。 首先,Helm v2使用的是基于服务器端的Tiller组件来管理应用程序的部署。Tiller在v2版本中负责与Kubernetes API进行交互,并跟踪应用程序的状态。然而,Tiller在安全性和性能方面存在一些问题,并且需要额外的配置和权限来正确运行。 为了解决这些问题,Helm v3于2019年发布,并移除了Tiller组件。在v3版本中,Helm完全依赖于Kubernetes API来进行应用程序的部署和管理。这种改变不仅提高了Helm的安全性和性能,还简化了Helm的安装和配置过程。 另一个重要的改变是Helm v3中引入了命名空间的概念。在Helm v2中,所有的应用程序都会部署到同一个默认的命名空间中,这可能导致应用程序之间的冲突。而在Helm v3中,每个应用程序都可以分配到不同的命名空间中,从而更好地隔离和管理应用程序。 此外,Helm v3还改进了依赖管理的方式。在Helm v2中,依赖被视为Helm Chart中的一个子图表,这导致了一些容易出错和难以维护的情况。在Helm v3中,依赖被视为外部的Chart,这使得依赖的安装和更新更加简单和可靠。 综上所述,Helm v3相较于v2来说,在安全性、性能、安装、配置、应用程序隔离和依赖管理等方面都有了一些重大的改进。因此,如果要选择使用Helm进行Kubernetes应用程序管理,推荐使用Helm v3以获得更好的体验和性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值