分享交流
合作共赢!

Kubernetes/K8S基础使用方法总结【十七】——helm

一、简介

Helm工作于Tiller,属于其客户端,通过操控Tiller,让tiller给kubernetes的api server接口通信来完成相关操作。Helm的工作管理方式与docker运行镜像先下载镜像的工作方式相似,先将chart文件下载到本地,默认用户家目录(如/root/.cache/helm/repository),然后通过配置文件将其执行为release文件即执行为kubernetes资源。

  • 官方仓库:https://hub.kubeapps.com/
  • helm官网:https://helm.sh/

helm相关内容:

  • Chart: 一个heml程序包,包含了应用及相关依赖等的配置清单文件;
  • Repository: Charts仓库,一般为https或http服务器;
  • Release: 特地的Chart部署于目标集群上的一个实例;
  • Tiller: 作为helm的服务端,接收helm发送的Charts和Config,合并生成Releas;

二、heml安装

1.下载

官方下载地址点击这里,然后选择自己环境对应版本进行下载,如我这里下载使用”Linux amd64 (checksum / 305cc92bc21c902a5337a9e1a63316ef67f6e06000d878cf22eb504c6750745c)”

2.部署

heml使用go语言开发,下载程序包只有一个helm的可执行文件,直接复制到/usr/bin/目录下,即可使用,详细操作如下。

[root@master1 helm]# ls
helm-v3.2.2-linux-amd64.tar.gz
[root@master1 helm]# tar -zxvf helm-v3.2.2-linux-amd64.tar.gz 
linux-amd64/
linux-amd64/helm
linux-amd64/README.md
linux-amd64/LICENSE
[root@master1 helm]# ls
helm-v3.2.2-linux-amd64.tar.gz linux-amd64
[root@master1 helm]# tree linux-amd64/
linux-amd64/
├── helm
├── LICENSE
└── README.md

0 directories, 3 files
[root@master1 helm]# cd linux-amd64/
[root@master1 linux-amd64]# ls
helm LICENSE README.md
[root@master1 linux-amd64]# cp -fa helm /usr/bin/

3.帮助命令

[root@master1 linux-amd64]# helm --help
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        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-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 "/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.

4.添加repo完成初始化

[root@master1 ~]# helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
[root@master1 ~]# helm repo list
NAME URL 
stable https://kubernetes-charts.storage.googleapis.com/
[root@master1 ~]# 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!⎈ 
[root@master1 ~]# helm version
version.BuildInfo{Version:"v3.2.2", GitCommit:"a6ea66349ae3015618da4f547677a14b9ecc09b3", GitTreeState:"clean", GoVersion:"go1.13.12"}

三、Helm常用命令

  1. 查看helm版本:helm version
  2. repo更新:helm repo update
  3. 搜索chart:helm search repo[hub] CHART
  4. 查看chart详细信息:helm show[inspect] all[chart][values][readme] CHART
  5. 获取release状态和提示信息:helm status CHART_NAME
  6. 部署chart:helm install –name NAME stable/CHART(如果指定配置文件可以添加选项-f –VALUESFILE)
  7. 对release进行增删改查回滚历史信息查看操作:helm install [delete,upgrade,rollback,list,history]
  8. chart相关操作:fetch/get(下载chart到本地);create(创建chart); inspect/show(查看chart详细信息);package(打包chart)
  9. chart语法检查:helm lint CHART_DIRECTORY
  10. chart install若提示名称已存在,想继续使用此名称,可以删除这个release:helm delete -purge CHART_NAME

四、Chart

1.chart架构

wordpress/
  Chart.yaml          # A YAML file containing information about the chart
  LICENSE             # OPTIONAL: A plain text file containing the license for the chart
  README.md           # OPTIONAL: A human-readable README file
  values.yaml         # The default configuration values for this chart
  values.schema.json  # OPTIONAL: A JSON Schema for imposing a structure on the values.yaml file
  charts/             # A directory containing any charts upon which this chart depends.
  crds/               # Custom Resource Definitions
  templates/          # A directory of templates that, when combined with values,
                      # will generate valid Kubernetes manifest files.
  templates/NOTES.txt # OPTIONAL: A plain text file containing short usage notes

每个文件的详细介绍参考官方文档:https://helm.sh/docs/topics/charts/

2.chart的创建

chart helm CHART_NAME,可以自动在当前目录创建一个chart,并且相关文件会自动生成。

[root@master1 ~]# helm create --help

This command creates a chart directory along with the common files and
directories used in a chart.

For example, 'helm create foo' will create a directory structure that looks
something like this:

    foo/
    ├── .helmignore   # Contains patterns to ignore when packaging Helm charts.
    ├── Chart.yaml    # Information about your chart
    ├── values.yaml   # The default values for your templates
    ├── charts/       # Charts that this chart depends on
    └── templates/    # The template files
        └── tests/    # The test files

'helm create' takes a path for an argument. If directories in the given path
do not exist, Helm will attempt to create them as it goes. If the given
destination exists and there are files in that directory, conflicting files
will be overwritten, but other files will be left alone.

Usage:
  helm create NAME [flags]

Flags:
  -h, --help             help for create
  -p, --starter string   the name or absolute path to Helm starter scaffold

Global 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
      --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 "/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
赞(0) 打赏
未经允许不得转载:琼杰笔记 » Kubernetes/K8S基础使用方法总结【十七】——helm

评论 抢沙发

评论前必须登录!

 

分享交流,合作共赢!

联系我们加入QQ群

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏