Prometheus+Grafana(外)监控Kubernetes(K8s)集群(基于containerd)

news/2025/1/12 9:59:18/

一、实验环境


1、k8s环境

版本v1.26.5

二进制安装Kubernetes(K8s)集群(基于containerd)—从零安装教程(带证书)

主机名IP系统版本安装服务
master0110.10.10.21rhel7.5nginx、etcd、api-server、scheduler、controller-manager、kubelet、proxy
master0210.10.10.22rhel7.5nginx、etcd、api-server、scheduler、controller-manager、kubelet、proxy
master0310.10.10.23rhel7.5nginx、etcd、api-server、scheduler、controller-manager、kubelet、proxy
node0110.10.10.24rhel7.5nginx、kubelet、proxy
node0210.10.10.25rhel7.5nginx、kubelet、proxy
master-lb10.10.10.30VIP

2、Prometheus+Grafana环境

Prometheus+Grafana监控系统

主机名IP系统版本
jenkins10.10.10.10rhel7.5

3、Prometheus部署方式

  • kubernetes内部Prometheus监控k8s集群
    • Prometheus监控内部K8S就是把Prometheus部署在K8S集群内,比如部署在K8S集群的monitoring的namespace下,因为K8S在所有的namespace下自动创建了serviceAccount和对应的Secret里自带访问K8S API的token和ca,所以就不需要手动创建serviceAccount和Secret了
  • kubernetes外部Prometheus监控k8s
    • kubernetes外部Prometheus监控外部K8S就是把Prometheus部署在虚拟机上,需要自己在Prometheus.yaml手动指定API的地址,ca和Token

4、版本对应

https://github.com/kubernetes/kube-state-metrics

在这里插入图片描述

二、配置kube-state-metrics


https://github.com/kubernetes/kube-state-metrics/tree/v2.9.2/examples/standard

1、文件下载

[root@master01 kube-state-metrics]# ls
cluster-role-binding.yaml  cluster-role.yaml  deployment.yaml  service-account.yaml  service.yaml
[root@master01 kube-state-metrics]# cat cluster-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:labels:app.kubernetes.io/component: exporterapp.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 2.9.2name: kube-state-metrics
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: kube-state-metrics
subjects:
- kind: ServiceAccountname: kube-state-metricsnamespace: kube-system
[root@master01 kube-state-metrics]# cat cluster-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:labels:app.kubernetes.io/component: exporterapp.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 2.9.2name: kube-state-metrics
rules:
- apiGroups:- ""resources:- configmaps- secrets- nodes- pods- services- serviceaccounts- resourcequotas- replicationcontrollers- limitranges- persistentvolumeclaims- persistentvolumes- namespaces- endpointsverbs:- list- watch
- apiGroups:- appsresources:- statefulsets- daemonsets- deployments- replicasetsverbs:- list- watch
- apiGroups:- batchresources:- cronjobs- jobsverbs:- list- watch
- apiGroups:- autoscalingresources:- horizontalpodautoscalersverbs:- list- watch
- apiGroups:- authentication.k8s.ioresources:- tokenreviewsverbs:- create
- apiGroups:- authorization.k8s.ioresources:- subjectaccessreviewsverbs:- create
- apiGroups:- policyresources:- poddisruptionbudgetsverbs:- list- watch
- apiGroups:- certificates.k8s.ioresources:- certificatesigningrequestsverbs:- list- watch
- apiGroups:- discovery.k8s.ioresources:- endpointslicesverbs:- list- watch
- apiGroups:- storage.k8s.ioresources:- storageclasses- volumeattachmentsverbs:- list- watch
- apiGroups:- admissionregistration.k8s.ioresources:- mutatingwebhookconfigurations- validatingwebhookconfigurationsverbs:- list- watch
- apiGroups:- networking.k8s.ioresources:- networkpolicies- ingressclasses- ingressesverbs:- list- watch
- apiGroups:- coordination.k8s.ioresources:- leasesverbs:- list- watch
- apiGroups:- rbac.authorization.k8s.ioresources:- clusterrolebindings- clusterroles- rolebindings- rolesverbs:- list- watch
[root@master01 kube-state-metrics]# cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:labels:app.kubernetes.io/component: exporterapp.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 2.9.2name: kube-state-metricsnamespace: kube-system
spec:replicas: 1selector:matchLabels:app.kubernetes.io/name: kube-state-metricstemplate:metadata:labels:app.kubernetes.io/component: exporterapp.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 2.9.2spec:automountServiceAccountToken: truecontainers:- image: bitnami/kube-state-metrics:2.9.2livenessProbe:httpGet:path: /healthzport: 8080initialDelaySeconds: 5timeoutSeconds: 5name: kube-state-metricsports:- containerPort: 8080name: http-metrics- containerPort: 8081name: telemetryreadinessProbe:httpGet:path: /port: 8081initialDelaySeconds: 5timeoutSeconds: 5securityContext:allowPrivilegeEscalation: falsecapabilities:drop:- ALLreadOnlyRootFilesystem: truerunAsNonRoot: truerunAsUser: 65534seccompProfile:type: RuntimeDefaultnodeSelector:kubernetes.io/os: linuxserviceAccountName: kube-state-metrics
[root@master01 kube-state-metrics]# cat service-account.yaml
apiVersion: v1
automountServiceAccountToken: false
kind: ServiceAccount
metadata:labels:app.kubernetes.io/component: exporterapp.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 2.9.2name: kube-state-metricsnamespace: kube-system
[root@master01 kube-state-metrics]# cat service.yaml
apiVersion: v1
kind: Service
metadata:labels:app.kubernetes.io/component: exporterapp.kubernetes.io/name: kube-state-metricsapp.kubernetes.io/version: 2.9.2name: kube-state-metricsnamespace: kube-system
spec:type: NodePortports:- name: http-metricsport: 8080targetPort: 8080nodePort: 32080protocol: TCP- name: telemetryport: 8081targetPort: 8081nodePort: 32081protocol: TCPselector:app.kubernetes.io/name: kube-state-metrics

2、安装kube-state-metrics

使用NodePort暴漏端口

[root@master01 kube-state-metrics]# kubectl apply -f ./
[root@master01 kube-state-metrics]# kubectl  get po -n kube-system -o wide | grep kube-state-metrics
kube-state-metrics-57ddc8c4ff-krsh2   1/1     Running   0             9m5s   10.0.3.1      master02   <none>           <none>[root@master01 kube-state-metrics]# kubectl get svc -n kube-system | grep kube-state-metrics
kube-state-metrics   NodePort    10.97.38.90     <none>        8080:32080/TCP,8081:32081/TCP   9m17s

3、测试结果

发现部署在master02,也就是10.10.10.22

[root@master01 kube-state-metrics]# curl http://10.97.38.90:8080/healthz -w '\n'
OK

在这里插入图片描述
在这里插入图片描述

三、配置Prometheus


1、修改prometheus.yml


[root@jenkins ~]# cat Prometheus/prometheus.yml- job_name: "kube-state-metrics"static_configs:- targets: ["10.10.10.22:32080"]- job_name: "kube-state-telemetry"static_configs:- targets: ["10.10.10.22:32081"]

2、重启Prometheus

[root@jenkins ~]# docker ps -a
CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS                       PORTS                    NAMES
a0497377cd82        grafana/grafana-enterprise          "/run.sh"                13 days ago         Up 3 minutes                 0.0.0.0:3000->3000/tcp   grafana
3e0e4270bd92        prom/prometheus                     "/bin/prometheus --c…"   13 days ago         Up 3 minutes                 0.0.0.0:9090->9090/tcp   prometheus[root@jenkins ~]# docker restart 3e0e4270bd92

3、登录查看结果

在这里插入图片描述

四、配置Grafana


推荐模板:13332、13824、14518

1、导入模板

在这里插入图片描述
在这里插入图片描述

2、查看结果

在这里插入图片描述


http://www.ppmy.cn/news/204529.html

相关文章

FutureTask简介

FutureTask简介 Future接口和实现Future接口的FutureTask类&#xff0c;代表异步计算的结果。FutureTask除了实现Future接口外&#xff0c;还实现了Runnable接口。因此&#xff0c;FutureTask可以交给Executor执行&#xff0c;也可以由调用线程直接执行&#xff08;FutureTask…

固态硬盘(Solid State Disk,SSD)

1、概念 固态硬盘&#xff08;Solid State Disk&#xff0c;SSD&#xff09;是一种基于NAND闪存的存储技术。SSD封装插到I/O总线上标准硬盘插槽&#xff08;通常是USB、SATA或IDE&#xff09;中。一个SSD封装由一个或多个闪存芯片和闪存翻译层&#xff08;flash translation l…

webstorm之——“卡死了”怎么办?

本人做前端项目超级喜欢用webstorm&#xff0c;主要原因还是因为它真的超级强大啊&#xff01; webstorm强大的功能就不多做介绍了。但是它的缺点也显而易见&#xff1a;吃内存。 电脑配置稍低一点&#xff0c;运行webstorm就特别容易卡顿&#xff0c;特别是项目比较大的时候…

解决webstorm卡顿问题

webstorm强大的功能就不多做介绍了。但是它的缺点也显而易见&#xff1a;吃内存。 电脑配置稍低一点&#xff0c;运行webstorm就特别容易卡顿&#xff0c;特别是项目比较大的时候&#xff0c;那卡顿得不要不要的。 在我的笔记本8g内存 256ssd的配置下&#xff0c;运行webstor…

世界上最大的计算机硬盘,三星:2.5英寸16TB,我是史上最大SSD硬盘-消费电子-与非网...

如果你对计算机硬盘空间有着非常高的要求&#xff0c;觉得1TB、2TB简直是渣&#xff0c;那么应该来看看三星最新发布的这款固态硬盘&#xff1a;PM1633a&#xff0c;注意是固态硬盘&#xff0c;它提供16TB的容量&#xff0c;尺寸还是2.5英寸。 严格说&#xff0c;其容量实际上是…

[BSidesSF2019]diskimage

题目链接 https://buuoj.cn/challenges#[BSidesSF2019]diskimage解题过程 binwalk分析好像很正常 用zsteg工具,发现镜像信息 zsteg -a attachment.png用下面的命令导出镜像信息&#xff1a; zsteg -e b8,rgb,lsb,xy attachment.png > disk.dat用testdisk分析下导出的镜像…

群晖DS918创建m.2 固态硬盘SSD读写缓存

群晖DS918创建m.2 固态硬盘SSD读写缓存 为了更好的浏览体验&#xff0c;欢迎光顾勤奋的凯尔森同学个人博客http://www.huerpu.cc:7000 首先要有两块SSD的硬盘。 点击存储池&#xff0c;创建ssd缓存 选择存储空间1 选择读写缓存 点击继续 选择DAID1 选择这两个磁盘 选择最大化…

笔记本固态硬盘温度测试软件,固态硬盘散热测试

固态硬盘散热测试 本次评测的ThinkPad T450标配256GB SSD固态硬盘。为了方便测试其性能&#xff0c;我们选择AS SSD Benchmark这款专门为SSD测试而设计的软件。可以测试出固态硬盘的持续读写性能&#xff0c;包括4KB小文件的传输性能等等&#xff0c;成绩显示可以分为两种&…