k8s的应用包管理工具helm的部署和使用

1、概述

我们一般是在k8s里面部署一些简单的应用,比如用deployment,daemonset,statefuleset的方式来部署应用,但是如果要部署一些复杂的应用,那么整个配置的编写、部署的过程就会变的更加的复杂,那么helm这个工具就可以来帮助解决这个复杂应用的部署问题。

helm可以类比与linux环境下yum部署应用的方式,只需要执行几条命令,就可以将应用需要的配置、依赖都部署到环境中。同样,helm也是通过几条简单的命令,将某个应用需要的配置、依赖都部署到了k8s集群上。

本文档就通过helm的安装和使用的角度来介绍下helm这个k8s的应用包管理工具。

2、helm中基本概念

在helm这个工具的使用中,主要有3个基本的概念需要了解:

Chart: chart就是helm中的包。类似yum安装中使用的rpm包。chart安装到k8s之后就是一个应用,那么chart中就包含了所有需要的资源的定义。

Repository: chart存放的位置。类似yum源的概念。

Release: chart在k8s集群中运行起来之后形成的实例。就类似与部署一个deployment要给一个名字一样。一个chart可以在同一个集群中被安装很多次,每一次的安装,都会创建一个新的release。就和拿一个redis的安装包可以安装很多次一样的。每次安装都有一个实例对应有自己的端口号,配置一样的。

那么针对以上的概念的说明,针对helm可以有如下的表述:

helm在chart仓库中获得chart,然后将chart安装到k8s集群中,每次安装都创建一个release.

3、helm的安装

可以通过预编译的二进制文件来安装helm的客户端命令,具体的版本可以到helm的github上去下载:

Releases · helm/helm · GitHub

本文档使用的版本:

https://get.helm.sh/helm-v3.7.2-linux-amd64.tar.gz

注意:安装在包含kubeconfig的主机上,这样helm就可以操作k8s集群来部署对应的应用,helm默认去"~/.kube/config"目录下获取kubeconfig来连接k8s集群。

安装过程

(1)先上传helm的压缩包到服务器

(2)解压并且复制helm命令

tar -zxf helm-v3.7.2-linux-amd64.tar.gz \
&& cd linux-amd64 \
cp helm /usr/local/bin/

(3)验证helm命令

输入helm命令,如果输出如下,则表示helm安装成功

[root@nccztsjb-node-11 linux-amd64]# 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                                                                       |
|------------------------------------|-----------------------------------------------------------------------------------|
| $HELM_CACHE_HOME                   | set an alternative location for storing cached files.                             |
| $HELM_CONFIG_HOME                  | set an alternative location for storing Helm configuration.                       |
| $HELM_DATA_HOME                    | set an alternative location for storing Helm data.                                |
| $HELM_DEBUG                        | indicate whether or not Helm is running in Debug mode                             |
| $HELM_DRIVER                       | set the backend storage driver. Values are: configmap, secret, memory, sql.       |
| $HELM_DRIVER_SQL_CONNECTION_STRING | set the connection string the SQL storage driver should use.                      |
| $HELM_MAX_HISTORY                  | set the maximum number of helm release history.                                   |
| $HELM_NAMESPACE                    | set the namespace used for the helm operations.                                   |
| $HELM_NO_PLUGINS                   | disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins.                        |
| $HELM_PLUGINS                      | set the path to the plugins directory                                             |
| $HELM_REGISTRY_CONFIG              | set the path to the registry config file.                                         |
| $HELM_REPOSITORY_CACHE             | set the path to the repository cache directory                                    |
| $HELM_REPOSITORY_CONFIG            | set the path to the repositories file.                                            |
| $KUBECONFIG                        | set an alternative Kubernetes configuration file (default "~/.kube/config")       |
| $HELM_KUBEAPISERVER                | set the Kubernetes API Server Endpoint for authentication                         |
| $HELM_KUBECAFILE                   | set the Kubernetes certificate authority file.                                    |
| $HELM_KUBEASGROUPS                 | set the Groups to use for impersonation using a comma-separated list.             |
| $HELM_KUBEASUSER                   | set the Username to impersonate for the operation.                                |
| $HELM_KUBECONTEXT                  | set the name of the kubeconfig context.                                           |
| $HELM_KUBETOKEN                    | set the Bearer KubeToken used for authentication.                                 |

Helm stores cache, configuration, and data based on the following configuration order:

- If a HELM_*_HOME environment variable is set, it will be used
- Otherwise, on systems supporting the XDG base directory specification, the XDG variables will be used
- When no other location is set a default location will be used based on the operating system

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 autocompletion scripts for the specified shell
  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 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值