目录
prometheus监控
部署prometheus
部署nginx监控实例
部署prometheus-adapter
prometheus监控
部署prometheus
创建项目仓库并上传镜像
[root@k8s2 helm]# vim prometheus-values.yaml
alertmanager:
alertmanagerSpec:
image:
repository: prometheus/alertmanager
tag: v0.24.0
grafana:
enabled: true
image:
repository: grafana/grafana
tag: 9.0.6
service:
type: LoadBalancer
adminPassword: prom-operator
sidecar:
image:
repository: kiwigrid/k8s-sidecar
tag: 1.19.2
kube-state-metrics:
image:
repository: kube-state-metrics/kube-state-metrics
tag: v2.5.0
prometheus-node-exporter:
image:
repository: prometheus/node-exporter
tag: v1.3.1
prometheusOperator:
admissionWebhooks:
patch:
enabled: true
image:
repository: ingress-nginx/kube-webhook-certgen
tag: v1.2.0
image:
repository: prometheus-operator/prometheus-operator
tag: v0.58.0
prometheusConfigReloader:
image:
repository: prometheus-operator/prometheus-config-reloader
tag: v0.58.0
thanosImage:
repository: thanos/thanos
tag: v0.27.0
prometheus:
service:
type: LoadBalancer
prometheusSpec:
image:
repository: prometheus/prometheus
tag: 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: true
serviceMonitor:
enabled: true
namespace: monitoring
labels:
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-adapter
tag: 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-nginx
namespace: default
spec:
minReplicas: 1
maxReplicas: 10
metrics:
- type: Pods
pods:
metric:
name: nginx_http_requests
target:
type: AverageValue
averageValue: 10
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: 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监控指标