kubernetes prometheus监控

目录

一、部署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"")}'
上传 

kubernetes prometheus监控_第1张图片

 部署项目  使用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

kubernetes prometheus监控_第2张图片

安装:

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  -

kubernetes prometheus监控_第3张图片

kubernetes prometheus监控_第4张图片 访问:

prometheus监控页面

kubernetes prometheus监控_第5张图片

访问grafana监控页面

默认用户/密码: admin/prom-operator

kubernetes prometheus监控_第6张图片

在import里边加载13105模板汉化 

kubernetes prometheus监控_第7张图片kubernetes prometheus监控_第8张图片

二、 部署nginx监控实例

上传对应版本所需要的镜像:  exporter监控

docker pull bitnami/nginx-exporter:0.11.0-debian-11-r369

kubernetes prometheus监控_第9张图片

kubernetes prometheus监控_第10张图片

修改chart包配置文件:

kubernetes prometheus监控_第11张图片kubernetes prometheus监控_第12张图片kubernetes prometheus监控_第13张图片

使用oci 上传 

kubernetes prometheus监控_第14张图片 kubernetes prometheus监控_第15张图片

部署应用

helm install myapp oci://reg.westos.org/charts/nginx

kubernetes prometheus监控_第16张图片kubernetes prometheus监控_第17张图片

测试:

kubernetes prometheus监控_第18张图片

三、部署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

kubernetes prometheus监控_第19张图片kubernetes prometheus监控_第20张图片kubernetes prometheus监控_第21张图片

删除原有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

kubernetes prometheus监控_第22张图片

压力测试:  

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

kubernetes prometheus监控_第23张图片

观察hpa动态弹缩

kubernetes prometheus监控_第24张图片

prometheus监控指标

kubernetes prometheus监控_第25张图片

回收:

kubernetes prometheus监控_第26张图片kubernetes prometheus监控_第27张图片

你可能感兴趣的:(kubernetes,kubernetes,prometheus,容器)