首页 文章 精选 留言 我的

精选列表

搜索[UI组件],共10000篇文章
优秀的个人博客,低调大师

全场景效能平台猪齿鱼 Agent——helm组件升级

此前文章猪齿鱼 Agent——基于GitOps的云原生持续交付模型介绍了Choerodon Agent基于helm2版本在猪齿鱼平台持续交付部署流水线中的作用以及实现原理。 现在最新helm版本已经到helm3,继续使用helm2会面临着如下问题: helm2版本使用的k8s api较老,不利于Choerodon Agent对k8s高版本进行支持 helm2架构是client-server架构。其中tiller-pod需要高集群权限,不方便集群中权限管理。同时在Choerodon Agent这边又属于客户端,出现问题后不方便进行调试 因此Choerodon Agent需要支持helm3版本,同时迁移helm2版本下安装的实例。 helm2与helm3区别 tiller被删除 如图所示,helm2中部署Release需要经过tiller-pod,但是在helm3就直接通过kubeconfig部署实例 helm2中Release是全局资源,在helm3中Release存储在各自的命名空间 Values支持JSON Schema校验器,自动检查所有输入的变量格式 移除了用于本地临时搭建Chart Repository的helm serve 命令 helm install 不再默认生成一个Release的名称,除非指定了–generate-name Helm Cli个别更名 helm2到helm3的迁移 helm2到helm3的迁移包括如下步骤: helm2的配置迁移 helm2的release迁移 清除helm2的配置、release数据以及Tileer deployment 使用helm-2to3进行数据迁移 安装2to3插件 helm3 plugin install https://github.com/helm/helm-2to3 插件特性 支持功能: 迁移helm2的配置 迁移helm2的releases 清除helm2的配置,rel ease 数据以及Tiller deployment 迁移helm2的配置 首先需要迁移helm2的配置和数据文件夹,包括如下内容: Chart starters Repositories Plugins 通过如下命令开始迁移: helm3 2to3 move config 迁移helm2的实例 通过如下命令开始迁 移: helm3 2to3 convert [ReleaseName] 清除helm2的数据 如果迁移完成后没有出现错误,就可以通过 此条命令清楚helm2的数据,包括如下内容: Configuration(Helm homedirectory) v2release data Tiller deployment 通过如下命令开始清楚数据: helm3 2to3 cleanup 注意:如果运行清楚命令,所有被删掉的 数据都不能恢复。所以没必要的话,还是将以前的数据保留下来 Choerodon Agent的升级处理 helm2到helm3的变动非常大,所以Choerdon Agent调用helm也发生巨大变化。其中有两部分需要进行修改 helm客户端获取、安装、升级、卸载实例需要重构 需要迁移helm2安装的实例到helm3,不然升级后Choerodon Agent无法继续管理以前的实例 helm客户端重构 在helm2的时候,Choerodon Agent直接将helm源代码作为Choerodon Agent部分代码进行使用。而在helm3,直接对helm3的源码进行二次开发,然后通过依赖引用。这样做的好处是将helm代码与Choerodon Agent代码解藕,有利于helm相关代码更新升级。 在Choerodon Agent里面,安装或升级实例会对Chart中的资源添加Choeordon Agent相关的label,比如choerodon.io/release、choeroodn.io/command等等,所以helm3的二次开发主要是添加资源label,以安装(Install)操作举例,其他操作(升级、删除)大同小异。 1. 修改模块名称 进行二次开发,首先需要修改该项目的模块名称,该步骤也是最麻烦的,因为修改后需要修改代码里面所有的包引用路径 如图所示,go.mod文件中的module进行如下修改 github.com/choerodon/helm => github.com/open-hand/helm 然后代码文件中修改引用路径 2. 加入添加label逻辑 通过断点调试,找到helm3安装逻辑由open-hand-helm/pkg/action/install.go::Run()方法实现,在该方法中插入添加标签步骤。下面省略不必要的代码 func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}, valsRaw string) (*release.Release, error) { // ···省略的步骤是helm对chart包进行校验渲染,生成k8s对象,并保存到resources变量中 // 以下为修改的内容,遍历resources对象,添加Label for _, r := range resources { err = action.AddLabel(i.ImagePullSecret, i.Command, i.AppServiceId, r, i.ChartVersion, i.ReleaseName, i.ChartName, i.AgentVersion, "", i.TestLabel, i.IsTest, false, nil) if err != nil { return nil, err } } // ···省略的步骤是helm将resources更新到集群中 } 接下来看看open-hand-helm/pkg/agent/action/label.go::AddLabel()方法 func AddLabel(imagePullSecret []v1.LocalObjectReference, command int64, appServiceId int64, info *resource.Info, version, releaseName, chartName, agentVersion, testLabel, namespace string, isTest bool, isUpgrade bool, clientSet *kubernetes.Clientset) error { // 该方法内容比较多,不在这里展示,具体可参考源代码。其作用就是根据不同的资源类型添加不同的Label值 } 3. Choerodon Agent 引用二次开发的helm库 参照helm3源码install命令的初始化方式,将分为以下几个步骤 获取helm配置信息 // 获取helm的配置信息 func getCfg(namespace string) (*action.Configuration, *cli.EnvSettings) { settings := cli.New() settings.SetNamespace(namespace) actionConfig := &action.Configuration{} helmDriver := os.Getenv("HELM_DRIVER") if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), helmDriver, debug); err != nil { log.Fatal(err) } return action config, settings } 创建Install操作对象 installClient := action.NewInstall( cfg, chartPathOptions, request.Command, request.ImagePullSecrets, request.Namespace, request.ReleaseName, request.ChartName, request.ChartVersion, request.AppServiceId, envkube.AgentVersion, "", false) 校验chart包并生成values值 ```go ··· valueOpts := getValueOpts(request.Values) p := getter.All(envSettings) vals, err := valueOpts.MergeValues(p) if err != nil { return nil, err } // Check chart dependencies to make sure all are present in /charts chartRequested, err := loader.Load(cp) if err != nil { return nil, err } validInstallableChart, err := isChartInstallable(chartRequested) if !validInstallableChart { return nil, err } ··· 4. 调用安装方法,执行安装命令 ```go ··· responseRelease, err := installClient.Run(chartRequested, vals, request.Values) ··· 具体的逻辑可查看choerodon-cluster-agent/pkg/helm/helm.go::InstallRelease() 总结来说就是以下4个步骤: 获取配置对象->生成操作对象->校验chart包并生成values值->执行操作 对已安装的Release进行迁移 对Release的迁移需要用到helm迁移工具,该工具是直接集成到Choerodon Agent项目代码中的。 在Choeordon Agent的启动逻辑中,接收到的第一个命令是agent_init。该命令负责命名空间的创建和监听,因此Release迁移逻辑也就放到这一步操作中。 整个流程如下图所示: 首先从choerodon-cluster-agent/pkg/command/agent/agent.go::InitAgent()方法开始 ```go func InitAgent(opts *commandutil.Opts, cmd *model.Packet) ([]*model.Packet, *model.Packet) { // ···省略的步骤是处理初始化的参数 // 下面的代码开始对需要监听的命名空间进行初始化 for _, envPara := range agentInitOpts.Envs { nsList = append(nsList, envPara.Namespace) err := createNamespace(opts, envPara.Namespace, envPara.Releases) if err != nil { return nil, commandutil.NewResponseError(cmd.Key, cmd.Type, err) } } // ···省略的步骤是开启gitops监听、controller监听、以及返回集群信息 } 2. 在[choerodon-cluster-agent/pkg/command/agent/agent.go::createNamespace()](https://github.com/open-hand/choerodon-cluster-agent/blob/master/pkg/command/agent/agent.go#L196)开始初始化命名空间 ```go func createNamespace(opts *commandutil.Opts, namespaceName string, releases []string) error { ns, err := opts.KubeClient.GetKubeClient().CoreV1().Namespaces().Get(namespaceName, metav1.GetOptions{}) if err != nil { // 如果命名空间不存在的话,则创建 if errors.IsNotFound(err) { _, err = opts.KubeClient.GetKubeClient().CoreV1().Namespaces().Create(&corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: namespaceName, Labels: map[string]string{model.HelmVersion: "helm3"}, }, }) return err } return err } labels := ns.Labels annotations := ns.Annotations // 如果命名空间存在,则检查labels标签 if _, ok := labels[model.HelmVersion]; !ok { // 开始迁移实例 return update(opts, releases, namespaceName, labels, annotations) } return nil } 在choerodon-cluster-agent/pkg/command/agent/agent.go::update()中迁移实例 ```go func update(opts *commandutil.Opts, releases []string, namespaceName string, labels, annotations map[string]string) error { releaseCount := len(releases) upgradeCount := 0 // 此处不对choerodon命名空间下的实例进行迁移处理 // 安装agent的时候,会直接创建choerodon命名空间而不打上 model.HelmVersion 标签 // 然后用户直接创建pv,会导致choerodon没有标签也纳入环境管理(如果通过agent安装了prometheus或者cert-manager就会出现问题) // 所以直接默认choeordon不需要进行helm迁移 if namespaceName != “choerodon” && releaseCount != 0 { for i := 0; i < releaseCount; i++ { getReleaseRequest := &helm.GetReleaseContentRequest{ ReleaseName: releases[i], Namespace: namespaceName, } // 查看该实例是否helm3管理,如果是upgradeCount加1,如果不是,进行迁移操作然后再加1 _, err := opts.HelmClient.GetRelease(getReleaseRequest) if err != nil { // 实例不存在有可能是实例未迁移,尝试迁移操作 if strings.Contains(err.Error(), helm.ErrReleaseNotFound) { helm2to3.RunConvert(releases[i]) if opts.ClearHelmHistory { helm2to3.RunCleanup(releases[i]) } upgradeCount++ } } else { // 实例存在表明实例被helm3管理,尝试进行数据清理,然后upgradeCount加1 if opts.ClearHelmHistory { helm2to3.RunCleanup(releases[i]) } upgradeCount++ } } if releaseCount != upgradeCount { return fmt.Errorf("env %s : failed to upgrade helm2 to helm3 ", namespaceName) } } // 添加label if labels == nil { labels = make(map[string]string) } labels[model.HelmVersion] = "helm3" _, err := opts.KubeClient.GetKubeClient().CoreV1().Namespaces().Update(&corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: namespaceName, Labels: labels, Annotations: annotations, }, }) return err } ``` 由此完成了Choerodon Agent对Release的迁移逻辑 常见问题解决 有时候Choerodon Agent重启后,会出现启动失败的问题,查看日志有实例迁移失败,tiller-pod不存在错误 该问题可能是实例迁移完成后,命名空间的label添加失败。解决办法是手动给该命名空间添加”choerodon.io/helm-version”:“helm3” 标签,以此表示该命名空间的实例迁移已完成,不需要再次迁移 修改资源后,部署失败,且错误信息提示为超时 首先在devops的环境层检查三个commit值是否一致,有如下情况: 前两个commit不一致:说明devops在gitlab的webhook回调处理上有问题,应该从gitlab的webhook执行记录以及devops日志进行排查 前两个一致,第三个落后于前两个:说明devops同步相关gitops操作已完成,但是在Choerodon Agent同步gitops库上出了问题。 这时先保留一份日志,供开发人员查找分析,然后kubectl -n choerodon delete [podName]删除Choerodon Agent进行重启。 如果重启完成后,Choerodon Agent仍然没有同步gitops库,这时应该考虑该环境库在gitlab的密钥是否与devops数据库中存储的一致。先在本地验证能否通过该密钥拉取gitops库。如果不行,重置该gitops库的密钥,最好的办法就是删掉该环境重新创建。如果可以,那么说明Choerodon Agent与gitlab连接有问题,检查gitlab的端口开发情况以及Choerodon Agent与外部网络的访问连接情况 三个commit都一致,但是实例部署失败,且提示访问chart仓库超时:这个问题经常遇到。排查后发现是Choerodon Agent与Chart Museum网络连接有问题 本文由猪齿鱼技术团队原创,转载请注明出处:猪齿鱼官网 关于猪齿鱼 猪齿鱼Choerodon全场景效能平台,提供体系化方法论和协作、测试、DevOps及容器工具,帮助企业拉通需求、设计、开发、部署、测试和运营流程,一站式提高管理效率和质量。从团队协同到DevOps工具链、从平台工具到体系化方法论,猪齿鱼全面满足协同管理与工程效率需求,贯穿端到端全流程,助力团队效能更快更强更稳定。戳此处试用猪齿鱼

优秀的个人博客,低调大师

OLAP引擎:基于Presto组件进行跨数据源分析

一、Presto概述 1、Presto简介 Presto是一个开源的分布式SQL查询引擎,适用于交互式分析查询,数据量支持GB到PB字节,Presto虽然具备解析SQL的能力,但它并不属于标准的数据库范畴。 Presto支持在线数据查询,包括Hive,关系数据库以及专有数据存储。一条Presto查询可以将多个数据源的数据进行合并,可以跨越整个组织进行分析,Presto主要用来处理响应时间小于1秒到几分钟的场景。 2、Presto架构 Presto查询引擎是基于Master-Slave的架构,运行在多台服务器上的分布式系统,由一个Coordinator节点和多个Worker节点组成,Coordinator负责解析SQL语句,生成执行计划,分发执行任务给Worker节点执行,Worker节点负责实际执行查询任务。 Coordinator节点 Coordinator服务器是用来解析查询语句,执行计划分析和管理Presto的Worker结点,跟踪每个Work的活动情况并协调查询语句的执行。Coordinator为每个查询建立模型,模型包含多个Stage,每个Stage再转为Task分发到不同的Worker上执行,协调通信基于REST-API,Presto安装必须有一个Coordinator节点。 Worker节点 Worker负责执行查询任务和处理数据,从Connector获取数据,Worker间会交换中间数据。Coordinator从Worker获取结果并返回最终结果给Client端,当Worker启动时会广播自己并发现Coordinator,告知Coordinator可用状态,协调通信基于REST-API,Presto通常会安装多个Worker节点。 数据源适配 Presto可以适配多种不同的数据源,可以和数据源连接和交互,Presto是通过表的完全限定名处理table,Catalog对应类数据源,Schema对应数据库,Table对应数据表。 Presto中处理的最小数据单元是一个Page对象,一个Page对象包含多个Block对象,每个Block对象是一个字节数组,存储一个字段的若干行,多个Block横切的一行是真实的一行数据。 二、Presto安装 1、安装包管理 [root@hop01 presto]# pwd /opt/presto [root@hop01 presto]# ll presto-cli-0.196-executable.jar presto-server-0.189.tar.gz [root@hop01 presto]# tar -zxvf presto-server-0.189.tar.gz 2、配置管理 在presto安装目录中创建etc文件夹,并添加以下配置信息: /opt/presto/presto-server-0.189/etc 节点属性 每个节点的特定环境配置:etc/node.properties; [root@hop01 etc]# vim node.properties node.environment=production node.id=presto01 node.data-dir=/opt/presto/data 配置内容:环境名称,唯一ID,数据目录。 JVM 配置 JVM的命令行选项,用于启动Java虚拟机的命令行选项列表:etc/jvm.config。 [root@hop01 etc]# vim jvm.config -server -Xmx16G -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError 配置属性 Presto服务器的配置,每个Presto服务器都可以充当协调器和工作器,如果单独使用一台机器来执行协调工作可以在更大的集群上提供最佳性能,这里PrestoServer既当一个coordinator也是一个worker节点:etc/config.properties。 [root@hop01 etc]# vim config.properties coordinator=true node-scheduler.include-coordinator=true http-server.http.port=8083 query.max-memory=3GB query.max-memory-per-node=1GB discovery-server.enabled=true discovery.uri=http://hop01:8083 这里coordinator=true表示当前Presto实例充当协调器角色。 日志配置 [root@hop01 etc]# vim log.properties com.facebook.presto=INFO Catalog属性 /opt/presto/presto-server-0.189/etc/catalog 配置hive适配: [root@hop01 catalog]# vim hive.properties connector.name=hive-hadoop2 hive.metastore.uri=thrift://192.168.37.133:9083 配置MySQL适配: [root@hop01 catalog]# vim mysql.properties connector.name=mysql connection-url=jdbc:mysql://192.168.37.133:3306 connection-user=root connection-password=123456 3、运行服务 启动命令 [root@hop01 /]# /opt/presto/presto-server-0.189/bin/launcher run 启动日志 这样presto就启动成功了。 三、客户端安装 1、Jar包管理 [root@hop01 presto-cli]# pwd /opt/presto/presto-cli [root@hop01 presto-cli]# ll presto-cli-0.196-executable.jar [root@hop01 presto-cli]# mv presto-cli-0.196-executable.jar presto-cli.jar 2、连接MySQL java -jar presto-cli.jar --server ip:9000 --catalog mysql --schema sq_export 四、源代码地址 GitHub·地址 https://github.com/cicadasmile/big-data-parent GitEE·地址 https://gitee.com/cicadasmile/big-data-parent

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码