zoukankan      html  css  js  c++  java
  • helm v3

    一、helm的引入

    当应用太多,yaml文件多、杂,管理和维护成本加重。引入helm包管理器,chart打包一堆yaml文件,统一部署。

    二、名词概念

    Chart

    打包到一起的一堆yaml文件,即k8s资源集合

    Config

    Config 指应用配置参数,在 Chart 中由 values.yaml 和命令行参数组成。Chart 采用 Go Template 的特性 + values.yaml 对部署的模板文件进行参数渲染,也可以通过 Helm Client 的命令
    --set key=value 的方式进行参数赋值。

    Repository

    类似于 Docker Hub,Helm 官方、阿里云等社区都提供了 Helm Repository,我们可以通过 helm repo add 导入仓库地址,便可以检索仓库并选择别人已经制作好的 Chart 包,开箱即用。

    Release

    Release 代表 Chart 在集群中的运行实例,同一个集群的同一个 Namespace 下 Release 名称是唯一的。Helm 围绕 Release 对应用提供了强大的生命周期管理能力,包括 Release 的查询、安装、更新、删除、回滚等。

    Tiller(v3版本中已去除)

    helm的服务端,用 Go 编写。它提供了一个与客户端连接的 gRPC 服务,它使用 Kubernetes 客户端库与 Kubernetes 进行通信。目前,该库使用 REST + JSON。

    Tiller 服务将信息存储在位于 Kubernetes 内的 ConfigMaps 中,它不需要自己的数据库。

    三、helm的优点

    1、实现把yaml文件整体管理;

    2、yaml文件高效复用;

    3、应用级别的版本管理;

    四、v3与v2的架构变化

    1、最大的改动就是移除了 Tiller 组件,所有功能都通过 Helm CLI 与 ApiServer 直接交互。

    2、release在v3版本中可以实现不同的namespace空间中重用;

    3、可以将chart推入到docker仓库中。

    五、helm  v3的安装

    v3的安装比v2简单快捷,不需要做授权操作,将二进制可执行文件放入到/usr/bin/即可

    wget https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz && tar xzvf helm-v3.2.1-linux-amd64.tar.gz -C /usr/loca/src && sudo mv /usr/local/src/linux-amd64/helm /usr/local/bin/
    

    1、官网   https://helm.sh/docs/

    2、解压安装

    # tar zxvf helm-v3.0.0-linux-amd64.tar.gz
    # cd linux-amd64/
    # ls
    helm  LICENSE  README.md
    # mv helm  /usr/bin/
    
    # helm   version 
    version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
    

    3、配置helm仓库

    https://help.aliyun.com/document_detail/131467.html   helm使用阿里私有仓库

    添加公有仓库如下
    # helm repo add apphub https://apphub.aliyuncs.com   添加Helm Hub “中国站”
    "apphub" has been added to your repositories
    
    # helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts  
    "stable" has been added to your repositories
    
    # helm repo list
    NAME      URL                                                   
    apphub    https://apphub.aliyuncs.com   (apphub和stable是自定义repo名称)                         
    stable    https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
    

    移除和更新仓库

    helm repo remove  仓库名
    
    helm repo  update
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "apphub" chart repository
    ...Successfully got an update from the "stable" chart repository
    Update Complete. ⎈ Happy Helming!⎈ 
    

    search搜索应用(指定repo所有仓库)

    # helm search repo  weave
    NAME              	CHART VERSION	APP VERSION	DESCRIPTION                                       
    apphub/weave-cloud	0.3.7        	1.4.0      	Weave Cloud is a add-on to Kubernetes which pro...
    apphub/weave-scope	1.1.8        	1.12.0     	A Helm chart for the Weave Scope cluster visual...
    stable/weave-cloud	0.1.2        	           	Weave Cloud is a add-on to Kubernetes which pro...
    stable/weave-scope	0.9.2        	1.6.5      	A Helm chart for the Weave Scope cluster visual...
    
    # helm search repo ${keyword}   查看所有的资源
    

    helm安装搜索的某个应用

    # helm install  ui  apphub/weave-scope  (ui自己取的名称)
    NAME: ui
    LAST DEPLOYED: Tue Sep 22 22:36:12 2020
    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 
    ui-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/
    

     

    修改ClusterIP为NodePort,部署成功。

     

     查看安装后的状态

    # helm list
    NAME	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART            	APP VERSION
    ui  	default  	1       	2020-09-22 23:03:12.207890113 +0800 CST	deployed	weave-scope-1.1.8	1.12.0     
    
    # helm status  ui
    NAME: ui
    LAST DEPLOYED: Tue Sep 22 23:03:12 2020
    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 
    ui-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/
    

    六、自定义chart

    1、生成一个chart模板

    # helm create ./chart-demo
    Creating ./chart-demo
    
    # cd chart-demo/
    # ls
    charts  Chart.yaml  templates  values.yaml
    注:templates里面存放自己的yaml文件   values.yaml存放全局变量,用于yaml的高复用  Chart.yaml用来定义一些chart的属性
    

    2、在templates 里面存放自己的yaml文件

    3、安装自定义chart

    heml  install  web  mychart/
    

    4、升级

    heml  upgrade   mychart/
    
    helm upgrade cloude-native-gitlab --values values.yaml gitlab-offical/gitlab
    

    5、查看release列表

    helm list --namespace ${namespace}
    

    七、chart资源的高复用

    传递参数,动态渲染模板,yaml的内容通过传参生成

    修改values.yaml文件,{{  .Release.Name}} {{  .Values.变量名}}

    还有待学习领悟

    八、chart包管理

    # 本地创建一个 Chart
    helm create <Chart 名称>
    
    // 安装helm-push插件,可能会卡
    [root@master01 msxu]# helm plugin install https://github.com/chartmuseum/helm-push.git
    
    # 推送 Chart 目录
    helm push <Chart 名称> <本地仓库名称>
    
    # 或者推送 Chart 压缩包
    helm push <Chart 名称>-<Chart 版本>.tgz <本地仓库名称>   
    
    # 从线上 Chart 仓库更新本地 Chart 索引
    helm repo update
    
    # 拉取 Chart
    helm fetch <本地仓库名称>/<Chart 名称> --version <Chart 版本>
    
    # 或者直接安装 Chart
    helm install -f values.yaml <本地仓库名称>/<Chart 名称> --version <Chart 版本>
    

    https://www.jianshu.com/p/11828ace23f9

    https://www.cnblogs.com/pythonPath/p/12667509.html  新工具kustomize

    https://segmentfault.com/a/1190000022583522?utm_source=tag-newest

    https://github.com/bitnami/charts/tree/master/bitnami  一个不错的heml仓库





  • 相关阅读:
    个人总结21
    个人总结08
    个人总结07
    构建之法读后感01
    学习进度表 03
    四则运算3
    求最大值
    学习进度表02
    四则运算 2
    学习进度表01
  • 原文地址:https://www.cnblogs.com/zjz20/p/13714772.html
Copyright © 2011-2022 走看看