kubernetes集群编排——prometheus监控

部署prometheus

创建项目仓库并上传镜像

kubernetes集群编排——prometheus监控_第1张图片

kubernetes集群编排——prometheus监控_第2张图片

编写配置文件

[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 -

kubernetes集群编排——prometheus监控_第3张图片

访问prometheus监控页面 http://192.168.92.103:9090/

kubernetes集群编排——prometheus监控_第4张图片

访问grafana监控页面  http://192.168.92.104/

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

kubernetes集群编排——prometheus监控_第5张图片

切换展示样式

kubernetes集群编排——prometheus监控_第6张图片

kubernetes集群编排——prometheus监控_第7张图片

kubernetes集群编排——prometheus监控_第8张图片

kubernetes集群编排——prometheus监控_第9张图片

部署nginx监控实例

上传镜像

kubernetes集群编排——prometheus监控_第10张图片

拉取所需的版本

[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

kubernetes集群编排——prometheus监控_第11张图片

查看状态

[root@k8s2 ~]# kubectl get pod

[root@k8s2 ~]# kubectl get svc

kubernetes集群编排——prometheus监控_第12张图片

测试

[root@k8s1 ~]# curl 192.168.92.102

kubernetes集群编排——prometheus监控_第13张图片

prometheus监控指标

kubernetes集群编排——prometheus监控_第14张图片

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

kubernetes集群编排——prometheus监控_第15张图片

[root@k8s2 ~]# kubectl api-versions

kubernetes集群编排——prometheus监控_第16张图片

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

kubernetes集群编排——prometheus监控_第17张图片

观察hpa动态弹缩

[root@k8s2 ~]# kubectl get hpa -w

kubernetes集群编排——prometheus监控_第18张图片

prometheus监控指标

kubernetes集群编排——prometheus监控_第19张图片

你可能感兴趣的:(kubernetes集群编排,kubernetes,prometheus,容器)