部署prometheus
创建项目仓库并上传镜像
编写配置文件
[root@k8s2 values]# 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
创建ns
[root@k8s2 helm]# kubectl create namespace monitoring
部署
[root@k8s2 helm]# helm -n monitoring install kube-prometheus-stack -f values/prometheus-values.yaml kube-prometheus-stack-39.11.0.tgz
查看状态
[root@k8s2 helm]# helm -n monitoring get manifest kube-prometheus-stack |kubectl get -f -
访问prometheus监控页面 http://192.168.92.103:9090/
访问grafana监控页面 http://192.168.92.104/
默认用户/密码: admin/prom-operator
切换展示样式
部署nginx监控实例
上传镜像
拉取所需的版本
[root@k8s2 helm]# helm pull my-repo/nginx --version 15.3.3
编写配置文件
[root@k8s2 values]# 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 values/nginx-values.yaml nginx-15.3.3.tgz
查看状态
[root@k8s2 ~]# kubectl get pod
[root@k8s2 ~]# kubectl get svc
测试
[root@k8s1 ~]# curl 192.168.92.102
prometheus监控指标
部署prometheus-adapter
编写配置文件
[root@k8s2 values]# 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 values/prometheus-adapter-values.yaml prometheus-adapter-3.4.0.tgz
查看状态
[root@k8s2 ~]# kubectl -n monitoring get pod
[root@k8s2 ~]# kubectl api-versions
删除原有hpa
[root@k8s2 helm]# kubectl delete hpa --all
新建hpa
[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动态弹缩
[root@k8s2 ~]# kubectl get hpa -w
prometheus监控指标