Helm 3.0介绍

Helm 是一个 Kubernetes 的包管理工具,就像 Linux 下的包管理器,如 yum/apt 等,可以 很方便的将之前打包好的 yaml 文件部署到 kubernetes 上。

Helm 有 3 个重要概念:

(1)helm:一个命令行客户端工具,主要用于 Kubernetes 应用 chart 的创建、打包、发 布和管理。
(2)Chart:应用描述,一系列用于描述 k8s 资源相关文件的yaml集合。
(3)Release:基于 Chart 的部署实体,一个 chart 被 Helm 运行后将会生成对应的一个 release;将在 k8s 中创建出真实运行的资源对象

helm chart —》.kube/config—》kube-apiserver—》资源文件

[root@master ~]# tar xf helm-v3.0.0-linux-amd64.tar.gz
[root@master ~]# ls
helm-v3.0.0-linux-amd64.tar.gz  ikube  linux-amd64
[root@master ~]# ls linux-amd64/
helm  LICENSE  README.md
[root@master ~]# mv linux-amd64/helm  /usr/bin/
[root@master ~]# 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       |
| $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 repo add stable http://mirror.azure.cn/kubernetes/charts 
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts 
helm repo update

查看配置的存储库

helm repo list 
helm search repo stable 

删除存储库:

helm repo remove aliyun

helm常用命令

(1)release相关的:

helm create mychart      //创建个chart,可以配置里面的信息
helm install   chart-test     mychart/			//用mychart模板,创建chart-test实例
helm install   .		创建一个release实例
helm upgrade [RELEASE] [CHART] [flags]  升级一个版本
helm rollback [flags] [RELEASE] [REVISION]  回滚一个版本
helm delete  release			删除创建的release
helm  history			查看历史
helm  status    获取release的状态信息

(2)chart相关的

helm  serach 
helm inspect 		查看chart的详细信息
helm  fetch 		把chart下载下来
helm  package  把chart打包

(2)release相关的

helm upgrade --set imageTag=1.17 web nginx 		#更改发布的配置
helm upgrade -f values.yaml web nginx 		#更改发布的配置
helm rollback test 1 		#将应用回滚到第一个版本
helm uninstall test  #卸载发行版
helm get all --revision 1 test  #查看历史版本配置信息 

(3)调试命令,确认信息

helm install chart-test  --debug --dry-run mychart/

使用 chart 部署一个应用

查找 chart

[root@master ~]# helm search repo weave
NAME                    CHART VERSION   APP VERSION     DESCRIPTION                       
aliyun/weave-cloud      0.1.2                           Weave Cloud is a add-on to...
aliyun/weave-scope      0.9.2           1.6.5           A Helm chart for the Weave ...
stable/weave-cloud      0.3.9           1.4.0           DEPRECATED - Weave Cloud is... 
stable/weave-scope      1.1.12          1.12.0          DEPRECATED - A Helm chart ...
[root@master ~]# helm fetch  aliyun/weave-scope

查看 chrt 信息

[root@master ~]# helm show chart aliyun/weave-scope
apiVersion: v1
appVersion: 1.6.5
description: A Helm chart for the Weave Scope cluster visualizer.
home: https://www.weave.works/oss/scope/
icon: https://avatars1.githubusercontent.com/u/9976052?s=64
keywords:
- containers
- dashboard
- monitoring
maintainers:
- email: github@orion-com.com
  name: omkensey
name: weave-scope
sources:
- https://github.com/weaveworks/scope
version: 0.9.2

安装包

[root@master ~]# helm install my-weave  stable/weave-scope
NAME: my-weave
LAST DEPLOYED: Mon May  2 02:55:41 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:

kubectl -n default port-forward $(kubectl -n default get endpoints \
my-weave-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040

then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:

https://www.weave.works/docs/scope/latest/introducing/

查看发布状态

[root@master ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                    APP VERSION
my-weave        default         1               2022-05-02 02:55:41.087638005 -0400 EDT deployed        weave-scope-1.1.12       1.12.0
[root@master ~]# helm status my-weave
NAME: my-weave
LAST DEPLOYED: Mon May  2 02:55:41 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:

kubectl -n default port-forward $(kubectl -n default get endpoints \
my-weave-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040

then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:

https://www.weave.works/docs/scope/latest/introducing/
[root@master ~]# kubectl get all
NAME                                                      READY   STATUS    RESTARTS   AGE
pod/weave-scope-agent-my-weave-cqv67                      1/1     Running   0          12m
pod/weave-scope-agent-my-weave-pw879                      1/1     Running   0          28s
pod/weave-scope-cluster-agent-my-weave-84fd7946c4-7vgwr   1/1     Running   0          12m
pod/weave-scope-frontend-my-weave-767c9cf7f5-78t44        1/1     Running   0          12m

NAME                              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                     AGE
service/kubernetes                ClusterIP   10.96.0.1        <none>        443/TCP                                     142d
service/my-weave-weave-scope      ClusterIP   10.108.172.101   <none>        80/TCP                                      12m


NAME                                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/weave-scope-agent-my-weave   2         2         2       2            2           <none>          12m

NAME                                                 READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/weave-scope-cluster-agent-my-weave   1/1     1            1           12m
deployment.apps/weave-scope-frontend-my-weave        1/1     1            1           12m

NAME                                                            DESIRED   CURRENT   READY   AGE
replicaset.apps/weave-scope-cluster-agent-my-weave-84fd7946c4   1         1         1       12m
replicaset.apps/weave-scope-frontend-my-weave-767c9cf7f5        1         1         1       12m

[root@master ~]# kubectl edit service/my-weave-weave-scope
...
  type: NodePort
[root@master ~]# kubectl get svc my-weave-weave-scope
NAME                   TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
my-weave-weave-scope   NodePort   10.108.172.101   <none>        80:30377/TCP   15m

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐