在k8s1.17.0中安装kube-prometheus

olivee 5年前 ⋅ 1129 阅读

参考

1. 下载安装文件

下载地址: https://github.com/oliveeli/kube-prometheus-for1.17.0

kube-prometheus-for1.17.0在标准的kube-prometheus上有一些修改。

修改信息如下:

1.1 manifests\kube-state-metrics-clusterRole.yaml文件涉及的修改

- apiGroups:
  - storage.k8s.io
  resources:
  - storageclasses
  - volumeattachments
  verbs:
  - list
  - watch
- apiGroups:
  - admissionregistration.k8s.io
  resources:
  - mutatingwebhookconfigurations
  - validatingwebhookconfigurations
  verbs:
  - list 
  - watch
- apiGroups:
  - networking.k8s.io 
  resources:
  - networkpolicies
  verbs:
  - list
  - watch

1.2 manifests\kube-state-metrics-deployment.yaml文件涉及的修改

由于kube-state-metrics:v1.9.0有bug,启动报错,因此回退到v1.7.2版本

        image: quay.io/coreos/kube-state-metrics:v1.7.2

2. 执行安装

kubectl create -f manifests/setup

kubectl create -f manifests/

kubectl apply -f  experimental/custom-metrics-api/

3. 查看apiservice是否正常

[root@fnl-master1 kube-prometheus-master]# kubectl get apiservice
NAME                                   SERVICE                         AVAILABLE   AGE
v1beta1.custom.metrics.k8s.io          monitoring/prometheus-adapter   True        2m33s
v1beta1.metrics.k8s.io                 monitoring/prometheus-adapter   True        68m

4. 查看hpa是否正常

[root@fnl-master1 kube-prometheus-master]# kubectl get hpa
NAME         REFERENCE               TARGETS     MINPODS   MAXPODS   REPLICAS   AGE
sample-app   Deployment/sample-app   400m/500m   1         10        1          3m46s

5. 压力测试

5.1 下载压测工具:

wget https://storage.googleapis.com/hey-release/hey_linux_amd64
chmod +x hey_linux_amd64 
mv hey_linux_amd64 /usr/local/bin/hey

5.2 代理待本地的8080测试端口:

kubectl port-forward svc/sample-app 8080

5.3 在新的shell窗口启动测试:

hey -c 20 -n 100000000 http://localhost:8080/metrics

5.4 在新的shell窗口查看hpa信息:

[root@fnl-master1 ~]# kubectl get hpa 
NAME         REFERENCE               TARGETS       MINPODS   MAXPODS   REPLICAS   AGE
sample-app   Deployment/sample-app   48848m/500m   1         10        10         20h

5.5 查看pod是否动态弹性扩展:

发现sample-app扩展到了10个:

[root@fnl-master1 ~]# kubectl get pod
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-5489c599c4-tbk85   1/1     Running   5          8d
sample-app-579bc6774c-4269b         1/1     Running   0          43s
sample-app-579bc6774c-86m9v         1/1     Running   1          20h
sample-app-579bc6774c-8br22         1/1     Running   0          42s
sample-app-579bc6774c-8d7lv         1/1     Running   0          12s
sample-app-579bc6774c-jv7lf         1/1     Running   0          12s
sample-app-579bc6774c-jvkw5         1/1     Running   0          27s
sample-app-579bc6774c-m9rc6         1/1     Running   0          42s
sample-app-579bc6774c-vsvm4         1/1     Running   0          27s
sample-app-579bc6774c-xrfsc         1/1     Running   0          27s
sample-app-579bc6774c-zj8tb         1/1     Running   0          27s