目录
prometheus监控
部署prometheus
部署nginx监控实例
部署prometheus-adapter
prometheus监控
部署prometheus
创建项目仓库并上传镜像
[root@k8s2 helm]# vim prometheus-values.yaml
alertmanager:alertmanagerSpec:image:repository: prometheus/alertmanagertag: v0.24.0
grafana:enabled: trueimage:repository: grafana/grafanatag: 9.0.6service:type: LoadBalanceradminPassword: prom-operatorsidecar:image:repository: kiwigrid/k8s-sidecartag: 1.19.2
kube-state-metrics:image:repository: kube-state-metrics/kube-state-metricstag: v2.5.0
prometheus-node-exporter:image:repository: prometheus/node-exportertag: v1.3.1
prometheusOperator:admissionWebhooks:patch:enabled: trueimage:repository: ingress-nginx/kube-webhook-certgentag: v1.2.0image:repository: prometheus-operator/prometheus-operatortag: v0.58.0prometheusConfigReloader:image:repository: prometheus-operator/prometheus-config-reloadertag: v0.58.0thanosImage:repository: thanos/thanostag: v0.27.0
prometheus:service:type: LoadBalancerprometheusSpec:image:repository: prometheus/prometheustag: v2.37.0
[root@k8s2 helm]# kubectl create namespace monitoring
[root@k8s2 helm]# helm -n monitoring install kube-prometheus-stack -f prometheus-values.yaml kube-prometheus-stack-39.11.0.tgz
[root@k8s2 helm]# helm -n monitoring get manifest kube-prometheus-stack |kubectl get -f -
访问方式为LoadBalancer
访问prometheus监控页面 http://192.168.81.103:9090/
访问grafana监控页面 http://192.168.81.104/
账号admin密码部署prometheus
导入中文模版
部署nginx监控实例
[root@k8s1 ~]# docker pull bitnami/nginx-exporter:0.11.0-debian-11-r368
[root@k8s2 helm]# helm pull bitnami/nginx --version 15.3.3
[root@k8s2 helm]# vim nginx-values.yaml
global:imageRegistry: reg.westos.org
metrics:enabled: trueserviceMonitor:enabled: truenamespace: monitoringlabels:release: kube-prometheus-stack
[root@k8s2 helm]# helm install myapp -f nginx-values.yaml nginx-15.3.3.tgz
prometheus监控指标
部署prometheus-adapter
[root@k8s2 helm]# vim prometheus-adapter-values.yaml
image:repository: prometheus-adapter/prometheus-adaptertag: v0.10.0
prometheus:url: http://kube-prometheus-stack-prometheus.monitoring.svc
[root@k8s2 helm]# helm -n monitoring install prometheus-adapter -f prometheus-adapter-values.yaml prometheus-adapter-3.4.0.tgz
删除原有hpa新建hpa
[root@k8s2 helm]# kubectl delete hpa --all
[root@k8s2 helm]# vim nginx-hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:name: myapp-nginxnamespace: default
spec:minReplicas: 1maxReplicas: 10metrics:- type: Podspods:metric:name: nginx_http_requeststarget:type: AverageValueaverageValue: 10scaleTargetRef:apiVersion: apps/v1kind: Deploymentname: myapp-nginx
[root@k8s2 helm]# kubectl apply -f nginx-hpa.yaml
压力测试
[root@k8s1 ~]# mv hey /usr/local/bin/
[root@k8s1 ~]# chmod +x /usr/local/bin/hey
[root@k8s1 ~]# hey -n 10000 -c 5 -q 10 http://myapp.westos.org/index.html
观察hpa动态弹缩
prometheus监控指标