目录
一、部署prometheus
二、 部署nginx监控实例
三、部署prometheus-adapter
一、部署prometheus
清理镜像方便后面一次性上传
docker rmi `docker images | grep -v REPOSITORY | awk '{print $1":"$2}'`
删除
docker load -i kube-prometheus-stack-0.58.0.tar 导入
docker tag reg.westos.org/prometheus-adapter/prometheus-adapter:v0.10.0 reg.westos.org/prometheus/prometheus-adapter:v0.10.0
docker tag reg.westos.org/grafana/grafana:9.0.6 reg.westos.org/prometheus/grafana:9.0.6
docker tag reg.westos.org/prometheus-operator/prometheus-config-reloader:v0.58.0 reg.westos.org/prometheus/prometheus-config-reloader:v0.58.0
docker tag reg.westos.org/prometheus-operator/prometheus-operator:v0.58.0 reg.westos.org/prometheus/prometheus-operator:v0.58.0
docker tag reg.westos.org/thanos/thanos:v0.27.0 reg.westos.org/prometheus/thanos:v0.27.0
docker tag reg.westos.org/kiwigrid/k8s-sidecar:1.19.2 reg.westos.org/prometheus/k8s-sidecar:1.19.2
docker tag reg.westos.org/kube-state-metrics/kube-state-metrics:v2.5.0 reg.westos.org/prometheus/kube-state-metrics:v2.5.0
docker tag reg.westos.org/ingress-nginx/kube-webhook-certgen:v1.2.0 reg.westos.org/prometheus/kube-webhook-certgen:v1.2.0
修改
docker images |grep reg.westos.org/prometheus/ | awk '{system("docker push "$1":"$2"")}'
上传
部署项目 使用yml文件helm安装
vim prometheus-values.yaml
alertmanager:
alertmanagerSpec:
image:
repository: prometheus/alertmanager
tag: v0.24.0
grafana:
enabled: true
image:
repository: prometheus/grafana
tag: 9.0.6
service:
type: LoadBalancer
adminPassword: prom-operator
sidecar:
image:
repository: prometheus/k8s-sidecar
tag: 1.19.2
kube-state-metrics:
image:
repository: prometheus/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: prometheus/kube-webhook-certgen
tag: v1.2.0
image:
repository: prometheus/prometheus-operator
tag: v0.58.0
prometheusConfigReloader:
image:
repository: prometheus/prometheus-config-reloader
tag: v0.58.0
thanosImage:
repository: prometheus/thanos
tag: v0.27.0
prometheus:
service:
type: LoadBalancer
prometheusSpec:
image:
repository: prometheus/prometheus
tag: v2.37.0
创建namespace
kubectl create namespace monitoring
安装:
helm -n monitoring install kube-prometheus-stack -f yml/prometheus-values.yaml kube-prometheus-stack-39.11.0.tgz
helm -n monitoring get manifest kube-prometheus-stack |kubectl get -f -
访问:
prometheus监控页面
访问grafana监控页面
默认用户/密码: admin/prom-operator
在import里边加载13105模板汉化
二、 部署nginx监控实例
上传对应版本所需要的镜像: exporter监控
docker pull bitnami/nginx-exporter:0.11.0-debian-11-r369
修改chart包配置文件:
使用oci 上传
部署应用
helm install myapp oci://reg.westos.org/charts/nginx
测试:
三、部署prometheus-adapter
前面以及上传所需镜像了
使用yml文件配置及部署
vim prometheus-adapter-values.yaml
image:
repository: prometheus/prometheus-adapter
tag: v0.10.0
prometheus:
url: http://kube-prometheus-stack-prometheus.monitoring.svc
helm -n monitoring install prometheus-adapter -f yml/prometheus-adapter-values.yaml prometheus-adapter-3.4.0.tgz
删除原有hpa
kubectl delete hpa --all
新建hpa
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
kubectl apply -f nginx-hpa.yaml
压力测试:
mv hey /usr/local/bin/
chmod +x /usr/local/bin/hey
hey -n 10000 -c 5 -q 10 http://192.168.67.125/index.html
观察hpa动态弹缩
prometheus监控指标
回收: