企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ### **编译cluterloader2** clone源码,由于我们测试的K8S版本为1.23,所以clone该版本的代码 ``` $ git clone -b release-1.23 https://github.com/kubernetes/perf-tests.git ``` 然后对源码做一些修改,具体修改参考 [附录一:Clusterloader2源码修改]()。 然后,编译二进制,这里我们编译 amd64 + linux 的二进制文件 ``` $ go env -w GOARCH=amd64 $ go env -w GOOS=linux $ cd perf-tests/clusterloader2/cmd $ go build -o clusterloader2 ``` ### **附录一:Clusterloader2源码修改** ##### **1、prometheus-apiserver-scrape-port** clusterloader2的该启动参数,指定当prometheus抓取apiserver指标时所使用的端口,默认为443。但是我们发现设置这个参数为6443并没有效果。 这里我们更改源码文件`pkg/prometheus/prometheus.go`,找到如下一行内容,从443改成6443 ``` flags.IntEnvVar(&p.APIServerScrapePort, "prometheus-apiserver-scrape-port", "PROMETHEUS_APISERVER_SCRAPE_PORT", 6443, "Port for scraping kube-apiserver (default 6443).") ``` 同时,更改`prometheus/manifests/master-ips/master-endpoints.yaml`文件,把如下一行也改成6443 ``` {{$PROMETHEUS_APISERVER_SCRAPE_PORT := DefaultParam .PROMETHEUS_APISERVER_SCRAPE_PORT 6443}} ``` ##### **2、node-exporter的安装** clusterloader2在安装node-exporter时,是通过ssh到master节点,然后以static pod的方式来安装的。这就需要master节点需要配置免密登录。这里我们更改源码文件`pkg/prometheus/prometheus.go`,不用clusterloader2来安装node-exporter,提示用户自己手动安装: ``` // runNodeExporter adds node-exporter as master's static manifest pod. // TODO(mborsz): Consider migrating to something less ugly, e.g. daemonset-based approach, // when master nodes have configured networking. func (pc *Controller) runNodeExporter() error { klog.V(2).Infof("Warning: Please install node-expoter on master mannually") return nil } ``` 在本实验中,一开始我们手动能daemonset方式安装,发现有点问题,最后是通过二进制进行安装的。需要注意的是,node-exporter暴露的端口要为9100,否则的话要更改`prometheus/manifests/master-ip/`目录下的三个文件中的配置。 ##### **3、监控etcd** clusterloader2最开始会通过master节点的2382端口(http)去获取监控etcd,如果失败则会ssh到master主机上,通过http://127.0.0.1:2379去监控etcd。 但实际上 kubeadm安装的k8s中,etcd暴露的端口为2381(注意kubeadm安装k8s时,etcd的监听地址要设置为0.0.0.0),因此我们需要改一下`prometheus/manifests/master-ip/master-endpoints.yaml`文件,把如下内容: ``` apiVersion: v1 kind: Endpoints ... - name: etcd-2379 port: 2379 - name: etcd-2382 port: 2382 ... ``` 改成如下,即删除etcd-2379和etcd-2382,增加etcd-2381 ``` apiVersion: v1 kind: Endpoints ... - name: etcd-2381 port: 2381 ... ``` 然后,`prometheus/manifests/master-ip/`下的master-service.yaml和master-serviceMonitor.yaml也要像上面一样做相应的修改。 然后,再修改`pkg/prometheus/prometheus.go`文件,找到isEtcdEndpoint函数,函数的内容改成如下: ``` func isEtcdEndpoint(endpoint string) bool { return endpoint == "etcd-2381" } ``` 最后,同样修改prometheus.go文件,找到isPrometheusReady函数,在expected targets注释那一行,把值从2改成1,这是因为删除了etcd-2329和etcd-2382,增加了etcd-2381: ``` func (pc *Controller) isPrometheusReady() (bool, error) { ... if pc.clusterLoaderConfig.PrometheusConfig.ScrapeEtcd { ... return CheckTargetsReady( // 1 out of 2 etcd targets should be ready. pc.framework.GetClientSets().GetClient(), func(t Target) bool { return isEtcdEndpoint(t.Labels["endpoint"]) }, 1, // expected targets: etcd-2379 and etcd-2382, 这一行原来的值为2,要改成1 1) // one of them should be healthy } ... } ``` ##### **4、prometheus manifests的其他更改** 最后,prometheus的manifests目录下的文件还有一些其他的修改,比如: - prometheus与grafana的镜像要改成国内能拉到的 - prometheus的数据存储默认为google的网盘存储,改成emptyDir或hostPath