美文网首页
Helm2和Helm3的安装\卸载\常用命令

Helm2和Helm3的安装\卸载\常用命令

作者: 彩色的炮灰 | 来源:发表于2023-04-20 17:30 被阅读0次

    文章目录

    Helm2和Helm3的安装与卸载

    关于Helm

    在Kubernetes上进行容器化部署并非易事,docker、环境变量、存储、网络等方面都会涉及到,这些复杂的操作可以被Helm应用包管理工具实现,避免了全手工操作的,Helm官网:https://helm.sh

    从Helm2到Helm3

    Helm是一个非常常用的K8s应用包管理工具,负责云原生应用的安装部署和生命周期管理。

    Helm2

    Helm2有两个主要的组件:

    • Tiller: helm的服务端,部署在k8s里面的一个pod,通常在kube-system这个系统空间里。主要负责部署helm charts,管理release,跟k8s API通信。
    • Helm Client: 主要负责从共有或者私有helm charts仓库拉取chart包,修改变量值,然后直接扔给tiller。

    Helm2的问题

    Helm2的一个主要问题是需要在k8s集群里面运行一个服务端,而这就需要把tiller的端口暴露给外界,会产生安全隐患。

    在helm 2中引入的tiller主要是当时k8s还没有RBAC机制,所以就引入了服务端tiller。

    而后来k8s的功能相应完善,加入了RBAC和CRD等,都使得tiller这个东西显得多余。

    Helm3

    helm3只有一个客户端,没有服务端,所以安装起来很方便,把相应的程序下下来即可,不需要helm init安装了。

    v3与v2的架构变化

    1、最大的改动就是移除了 Tiller 组件,所有功能都通过 Helm CLI 与 ApiServer 直接交互。
    2、release在v3版本中可以实现不同的namespace空间中重用;
    3、可以将chart推入到docker仓库中。
    [图片上传失败...(image-7e563b-1682067597633)]

    相对于helm2,helm3有几大特性:

    • 移除了tiller
    • 支持分布式helm hub, 有了它就可以在很多时候不需要手动添加非官方repo了,例如helm3 search hub
    • 为chart输入值进行json schema验证。
    • 可以给helm charts添加test了,通过helm test 就能针对部署的应用跑一些tests。
    • 部署的时候release name必须指定了,helm2的时候不指定会自动生成一个。
    • 删除的时候不需要–purge了,删了就是删了。

    Helm2卸载

    helm 安装失败 需要删除tiller,关于版本的话 直接覆盖就可以了

    # 删除 与tiller相关的secrets,sa,clusterrolebinding
    kubectl get -n kube-system secrets,sa,clusterrolebinding -o name|grep tiller|xargs kubectl -n kube-system delete
    
    # 删除 与helm客户端相关的资源
    kubectl get all -n kube-system -l app=helm -o name|xargs kubectl delete -n kube-system
    
    

    Helm2的安装

    本次实战环境是kubernetes集群(1.20版本),由三台CentOS7.7服务器组成;
    部署完毕后,在体验Helm的环节,需要您提前准备好NFS,作为部署应用的网络存储空间;

    部署客户端

    ssh登录到可以执行kubectl操作的服务器:

    wget https://get.helm.sh/helm-v2.16.2-linux-amd64.tar.gz
    # 解压:
    tar -zxvf helm-v2.16.2-linux-amd64.tar.gz
    
    # 把解压后的文件夹内的helm文件放入/usr/local/bin/:
    mv linux-amd64/helm /usr/local/bin/
    
    #查看helm版本,如下,可见客户端版本是2.16.2,由于helm服务端(名为tiller)还没有部署,因此显示"could not find tiller":
    [root@node1 ~]# helm version
    Client: &version.Version{SemVer:"v2.16.2", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
    Error: could not find tiller
    
    

    部署tiller

    客户端部署完毕,接下来要把ServiceAccount和角色绑定建好

    # 账号与角色绑定
    # 创建名为tiller的ServiceAccount:
    kubectl create serviceaccount --namespace kube-system tiller
    
    # 把tiller与角色tiller-cluster-rule进行绑定:
    kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
    
    # helm初始化,其中tiller的镜像来自阿里云,并且将默认仓库也设置为阿里云的:
    
    helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.16.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts --service-account tiller
    
    # 等待控制台提示成功后再次执行helm version,输出如下,可见helm的服务端已经返回了信息:
    [root@master-1 ~]# helm version
    Client: &version.Version{SemVer:"v2.16.2", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
    Server: &version.Version{SemVer:"v2.16.2", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
    
    

    现在helm已装好,接下来部署个应用试试

    Helm2常用命令

    查看版本
    helm version
    查看当前安装的charts
    helm list
    查询 charts
    helm search redis
    安装charts
    helm install --name redis --namespaces prod bitnami/redis
    查看charts状态
    helm status redis
    删除charts
    helm delete --purge redis
    增加repo
    helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
    helm repo add --username admin --password password myharbor https://harbor.qing.cn/chartrepo/charts
    更新repo仓库资源
    helm repo update
    创建charts
    helm create helm_charts
    测试charts语法
    helm lint
    打包charts
    cd helm_charts && helm package ./
    查看生成的yaml文件
    helm template helm_charts-0.1.1.tgz
    更新image
    helm upgrade --set image.tag=‘v2019-05-09-18-48-40’ study-api-en-oral myharbor/study-api-en-oral
    回滚relase
    helm hist study-api-en-oral
    helm rollback study-api-en-oral 4

    Helm2到Helm3的迁移

    helm官方提供了一个小公举,帮助我们把已经部署的helm2应用迁移到helm3上。

    • 安装插件
    $ helm3 plugin install https://github.com/helm/helm-2to3
    
    
    • 迁移helm2的配置,例如仓库
    $ helm3 2to3 move config
    
    
    • 迁移helm2部署的应用(确保helm2和helm3同时安装在同一台机器上)
    $ helm3 2to3 convert <release-name> --delete-v2-releases
    
    

    Helm3安装

    二进制安装

    # 根据操作系统去获取最新二进制安装包https://github.com/helm/helm/releases       
    wget https://get.helm.sh/helm-v3.3.1-linux-amd64.tar.gz       
    # 由于helm包在国外,我通过ss拉到了腾讯云cos,国内可通过以下地址访问:https://download.osichina.net/tools/k8s/helm/helm-v3.3.1-linux-amd64.tar.gz       
    tar -zxvf helm-v3.3.1-linux-amd64.tar.gz       
    cp linux-amd64/helm /usr/local/bin/
    
    

    helm其他安装可参考官方网站: https://helm.sh/docs/intro/install/
    注意: helm 客户端需要下载到安装了 kubectl 并且能执行能正常通过 kubectl 操作 kubernetes 的服务器上, 否则 helm 将不可用

    配置repo

    helm repo add  elastic    https://helm.elastic.co       
    helm repo add  gitlab     https://charts.gitlab.io       
    helm repo add  harbor     https://helm.goharbor.io       
    helm repo add  bitnami    https://charts.bitnami.com/bitnami       
    helm repo add  incubator  https://kubernetes-charts-incubator.storage.googleapis.com       
    helm repo add  stable     https://kubernetes-charts.storage.googleapis.com       
    # 添加国内仓库       
    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       
    
    

    helm3 命令使用总结记录

    但是了helm 命令众多,参数又多,全靠记忆肯定不行的,几个月不用 不就忘记完了嘛

    所有此文既是复习helm命令,也是将这些命令 结构化的总结记录下来

    本文中以nginx chart为例,使用时请注意替换

    信息命令

    包含helm自身信息的命令

    查看环境信息

    helm env 
    
    

    查看版本信息

    helm version
    
    

    仓库命令

    跟仓库操作有关的命令,经常使用

    查找软件

    helm search repo nginx 
    helm search hub  nginx 
    
    

    Available Commands:
    hub search for charts in the Helm Hub or an instance of Monocular
    repo search repositories for a keyword in charts

    新增一个仓库

    helm repo add bitnami https://charts.bitnami.com/bitnami
    
    

    查看已有仓库列表

    helm repo list 
    
    

    更新仓库资源

    helm repo update
    
    

    删除一个仓库

    helm repo delete bitnami
    
    

    创建仓库引索

    helm repo index /root/helm/repo
    

    部署管理命令

    此部分包括部署应用和管理应用等一系列操作,使用非常频发

    部署chart并指定版本

    helm install center-nginx bitnami/nginx --version 9.4.1
    
    

    卸载chart

    helm uninstall center-nginx
    
    

    chart状态查看

    helm status center-nginx
    
    

    简介
    该命令显示已命名发布的状态,状态包括:

    • 最后部署时间
    • 发布版本所在的k8s命名空间
    • 发布状态(可以是: unknown, deployed, uninstalled, superseded, failed, uninstalling, pending-install, pending-upgrade 或 pending-rollback)
    • 发布版本修订
    • 发布版本描述(可以是完成信息或错误信息,需要用–show-desc启用)
    • 列举版本包含的资源,按类型排序
    • 最后一次测试套件运行的详细信息(如果使用)
    • chart提供的额外的注释

    查看chart列表

    -A 表所有namespace

    helm list -A 
    
    

    chart部署历史记录

    helm history center-nginx
    
    

    chart更新

    helm upgrade --set image.tag=nginx.18 center-nginx bitnami/nginx
    
    

    chart回滚

    helm rollback center-nginx 2
    
    

    chart制作命令

    此部分包括了chart下载,和制作chart包相关命令

    下载chart包

    helm pull bitnami/nginx
    
    

    检查chart包语法

    helm lint 
    
    

    渲染模式测试chart包

    helm install --debug --dry-run testchart .
    
    

    创建chart包

    helm create testchart
    
    

    上传chart包到私服

    helm push nginx-9.4.1.tgz chartmuseum --debug
    
    

    chart信息命令

    chart在helm里面是一种资源集合,也是一种格式,在安装使用之前我们可以查看 相关的信息

    由于helm show中的readme values all等价值不大,且展示的信息过多,这里不记录了,很少很少会用,因为用展示内容太多了,还不如去页面上看

    查看chart包信息

    显示chart包的版本,源码等信息

    helm show chart bitnami/nginx
    

    release信息命令

    release在helm的概念是已经部署了的chart(不包括k8s是否部署成功),此类命令在部署后排错用,因为此类命令显示的信息 其他命令也有实现,所有使用不多

    查看release 注释

    helm get notes center-nginx
    

    查看release 修改的值

    如果是install之后没修改过,就是null

    helm get values center-nginx
    
    

    查看release 钩子

    helm get hooks center-nginx
    
    

    查看manifest 配置文件

    这个manifest配置文件就是kubernetes中资源配置文件,名称一样

    helm get manifest center-nginx
    
    

    查看release 所有信息

    就是上面4个命令的值的聚合

    helm get all center-nginx
    
    

    插件命令

    此部分列出 插件命令,使用较少

    安装插件

    helm plugin install https://github.com/chartmuseum/helm-push.git
    
    

    插件列表

    helm plugin list
    
    

    卸载插件

    helm plugin pluginName
    
    

    更新插件

    helm plugin update pluginName
    
    

    Helm安装nfs storageclasses

    安装nfs

    yum -y install epel-release       yum -y install nfs-utils rpcbind       systemctl enable rpcbind nfs-server nfs-lock nfs-idmap       systemctl start rpcbind nfs-server nfs-lock nfs-idmap       # 172.18.4.*的IP都能访问nfs       echo "/data 172.18.4.*(rw,sync,no_root_squash)" >  /etc/exports       exportfs -a       
    
    

    安装nfs storageclasses

    helm pull stable/nfs-client-provisioner --untar       cd nfs-client-provisioner/vim values.yaml       helm install nfs -f values.yaml .
    
    

    values.yaml

    ...nfs:  server: 172.18.4.202         path: /data/nfs         mountOptions:...
    
    

    Helm 2和Helm 3在使用上还是有些区别的,除了在Helm 3中移除了Tiller,一些常用的命令也发生了变化,在这篇文章中进行简单的整理。

    常用命令一览

    命令 Helm 2 Helm 3 命令说明区别 命令说明
    create create a new chart with the given name
    delete - given a release name, delete the release from Kubernetes
    dependency manage a chart’s dependencies
    fetch - download a chart from a repository and (optionally) unpack it in local directory
    get download a named release
    history fetch release history
    home - displays the location of HELM_HOME
    init - initialize Helm on both client and server
    inspect - inspect a chart
    install install a chart archive
    lint examines a chart for possible issues
    list list releases
    package package a chart directory into a chart archive
    plugin add, list, or remove Helm plugins
    repo add, list, remove, update, and index chart repositories
    reset - uninstalls Tiller from a cluster
    rollback roll back a release to a previous revision
    search search for a keyword in charts
    serve - start a local http web server
    status displays the status of the named release
    template locally render templates
    test test 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/server version information
    env - Helm client environment information
    help - Help about any command
    pull - download a chart from a repository and (optionally) unpack it in local directory
    show - show information of a chart
    uninstall - uninstall a release

    Helm 3: 不再存在的Helm 2的命令

    在前面的文章示例中,我们发现helm init已经在Helm 3中不存在了。类似的共有如下7条命令,在Helm 3中或删除或改名或则功能增强,比如因为Tiller的去除,所以导致了reset命令没有存在的意义,同时init存在仅剩客户端需要设定的功能,所以被去除了。另外诸如fetch命令,而在Helm 3中提供了pull命令予以替代。本来home命令用于显示HELM_HOME环境变量,而在Helm 3中提供env命令可以显示所有的环境变量信息,用增强的功能予以了替换。但是论如何,总之已经法在Helm 3中直接使用如下7条命令。

    命令 Helm 2 Helm 3 命令说明
    delete given a release name, delete the release from Kubernetes
    fetch download a chart from a repository and (optionally) unpack it in local directory
    home displays the location of HELM_HOME
    init initialize Helm on both client and server
    inspect inspect a chart
    reset uninstalls Tiller from a cluster
    serve start a local http web server

    Helm 3: 相较与Helm 2新增的命令

    相较于Helm 2,从helm --help中获得的信息看到如下5条命令在Helm 3中为新增的命令。

    命令 Helm 2 Helm 3 命令说明
    env Helm client environment information
    help Help about any command
    pull download a chart from a repository and (optionally) unpack it in local directory
    show show information of a chart
    uninstall uninstall a release

    稍作分析,会发现如下事实:

    • env是对被删除的命令home的强化
    • pull是对被删除的命令fetch的替换
    • show是对被删除的命令inspect的替换
    • help命令本身在Helm 2时代就可以使用,只是helm --help里面没有显示,算是文档自包含的强化
    • uninstall是功能特性的增强

    Helm 3: 命令说明发生变化

    由于Tiller的移除,版本显示命令helm version的表述从显示client/server的版本信息变成了显示client的版本信息,类似的发生变化的共有5条命令,到底是文档的变化还是功能性的反映,在后续的文章中将继续通过实例进行进一步的说明。

    命令 Helm 2 Helm 3 命令说明区别 Helm 2 命令说明 Helm 3命令说明
    get download a named release download extended information of a named release
    install install a chart archive install a chart
    plugin add, list, or remove Helm plugins install, list, or uninstall Helm plugins
    test test a release run tests for a release
    version print the client/server version information print the client version information

    Helm 3: 其他变化

    并不是说helm --help没有变化的,使用上就没有区别,以repo和install为例,在使用上都发生了变化,但是在helm自身提供的帮助信息中却未提供,这些也会在后续的示例的使用中进一步进行说明。

    Helm 2 到Helm 3的升级

    helm还提供了一个移植的插件,详细可参看:

    本文用于对比的Helm 命令取之与Helm 2.8.2和Helm 3.0.0。

    Helm版本支持策略

    该文档描述了在Helm和Kubernetes之间支持的最大版本偏差。

    支持的版本

    Helm的版本用 x.y.z 描述,x是主版本,y是次版本,z是补丁版本,遵循 语义化版本 术语。

    Helm项目维护了一个针对最近次要版本的发布分支。适当的修复,包括安全修复、从发布分支中的cherry-pick, 视严重程度而定。更多细节请查看 Helm版本策略

    可支持的版本偏差

    当一个Helm的新版本发布时,它是针对Kubernetes的一个特定的次版本编译的。比如,Helm 3.0.0 与Kubernetes的1.16.2的客户端版本交互,一次可以兼容Kubernetes 1.16。

    从Helm 3开始,Helm 编译时假定与针对n-3版本的Kubernetes兼容。由于Helm 2对Kubernetes次版本变更的支持稍微严格一点, 则假定与Kubernetes的n-1版本兼容。

    例如,如果您在使用一个针对Kubernetes 1.17客户端API版本编译的Helm 3版本,那么它应该可以安全地使用Kubernetes 1.17, 1.16,1.15,以及1.14。如果您在使用一个针对Kubernetes 1.16客户端API版本编译的Helm 2版本,那么它应该可以安全地使用 Kubernetes 1.16 和 1.15。

    不推荐将Helm用于比编译它所依赖的版本更高的Kubernetes版本,因为Helm并没有做出任何向前兼容的保证。

    如果您选择了一个Kubernetes版本不支持的Helm,需自负风险。

    请参考下表来确定哪个版本的Helm与您的集群兼容。

    Helm 版本 支持的 Kubernetes 版本
    3.7.x 1.22.x - 1.19.x
    3.6.x 1.21.x - 1.18.x
    3.5.x 1.20.x - 1.17.x
    3.4.x 1.19.x - 1.16.x
    3.3.x 1.18.x - 1.15.x
    3.2.x 1.18.x - 1.15.x
    3.1.x 1.17.x - 1.14.x
    3.0.x 1.16.x - 1.13.x
    2.16.x 1.16.x - 1.15.x
    2.15.x 1.15.x - 1.14.x
    2.14.x 1.14.x - 1.13.x
    2.13.x 1.13.x - 1.12.x
    2.12.x 1.12.x - 1.11.x
    2.11.x 1.11.x - 1.10.x
    2.10.x 1.10.x - 1.9.x
    2.9.x 1.10.x - 1.9.x
    2.8.x 1.9.x - 1.8.x
    2.7.x 1.8.x - 1.7.x
    2.6.x 1.7.x - 1.6.x
    2.5.x 1.6.x - 1.5.x
    2.4.x 1.6.x - 1.5.x
    2.3.x 1.5.x - 1.4.x
    2.2.x 1.5.x - 1.4.x
    2.1.x 1.5.x - 1.4.x
    2.0.x 1.4.x - 1.3.x

    参考链接:

    https://cloud.tencent.com/developer/article/1694640
    https://devopscube.com/install-configure-helm-kubernetes/
    https://www.qikqiak.com/k8s-book/docs/42.Helm%E5%AE%89%E8%A3%85.html
    https://github.com/helm/helm-2to3
    https://helm.sh/zh/docs/

    原文地址:https://huaweicloud.csdn.net/63311cebd3efff3090b528d9.html#Helm2Helm3_1

    相关文章

      网友评论

          本文标题:Helm2和Helm3的安装\卸载\常用命令

          本文链接:https://www.haomeiwen.com/subject/eearjdtx.html