当前位置:网站首页>Kubernetes 服务发现 监控APIServer
Kubernetes 服务发现 监控APIServer
2022-04-21 11:55:00 【富士康质检员张全蛋】
监控 APIServer
APIServer 作为 Kubernetes 最核心的组件,当然他的监控也是非常有必要的,对于 APIServer 的监控我们可以直接通过 Kubernetes 的 Service 来获取:
* kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 33d
上面这个 Service 就是我们集群的 apiserver 在集群内部的 Service 地址,要自动发现 Service 类型的服务,我们就需要用到 role 为 Endpoints 的 kubernetes_sd_configs,我们可以在 ConfigMap 对象中添加上一个 Endpoints 类型的服务的监控任务:
- job_name: "apiservers"
kubernetes_sd_configs:
- role: endpoints
上面这个任务是定义的一个类型为 endpoints 的 kubernetes_sd_configs ,添加到 Prometheus 的 ConfigMap 的配置文件中,然后更新配置:
* kubectl apply -f https://p8s.io/docs/k8s/manifests/prometheus/config-8.yaml
# 隔一会儿执行reload操作
* curl -X POST "http://10.244.2.46:9090/-/reload"
更新完成后,我们再去查看 Prometheus 的 Dashboard 的 target 页面:(因为没有办法保证所有的endpoints都有我们对应的metrics接口的,所以出现下面down的状态)

我们可以看到 apiservers 任务下面出现了很多实例,这是因为这里我们使用的是 Endpoints 类型的服务发现,所以 Prometheus 把所有的 Endpoints 服务都抓取过来了,同样的,上面我们需要的服务名为 kubernetes 这个 apiserver 的服务也在这个列表之中,那么我们应该怎样来过滤出这个服务来呢?
同样还是需要使用relabel_configs 这个配置,只是我们这里不是使用 replace 这个动作了,而是 keep,就是只把符合我们要求的给保留下来,哪些才是符合我们要求的呢?
我们要过滤的服务是 default 这个 namespace 下面,服务名为 kubernetes 的元数据,所以这里我们就可以根据对应的 __meta_kubernetes_namespace 和 __meta_kubernetes_service_name 这两个元数据来进行过滤,另外由于 kubernetes 这个服务对应的端口是 443,需要使用 https 协议,所以这里我们需要使用 https 的协议,对应的就需要将 ca 证书配置上,如下所示:
- job_name: "apiservers"
kubernetes_sd_configs:
- role: endpoints
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
relabel_configs:
- source_labels:
[
__meta_kubernetes_namespace,
__meta_kubernetes_service_name,
__meta_kubernetes_endpoint_port_name,
]
action: keep
regex: default;kubernetes;https
现在重新更新配置文件、重新加载 Prometheus,切换到 Prometheus 的 Targets 路径下查看:

现在可以看到 apiserver 这个任务下面只有 apiserver 这一个实例了,现在我们切换到 Graph 路径下面查看下采集到的数据,比如查询 apiserver 的总的请求数:

这样我们就完成了对 Kubernetes APIServer 的监控。
版权声明
本文为[富士康质检员张全蛋]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_34556414/article/details/124312429
边栏推荐
- One day, Alibaba database will squeeze Oracle out of the market
- leaflet军事标绘-突击方向修改(leaflet篇.90)
- IIR second order filter in flight control
- 京东云分布式数据库StarDB顺利完成多方国产化适配认证
- Leetcode daily question: 824 Goat Latin
- 如何跨域请求携带 cookie ?
- HMS Core 6.4.0版本发布公告
- How to carry cookies in cross domain requests?
- InfoQ settled Express
- 世界读书日|数据库经典书籍推荐书单(文末留言免费送)
猜你喜欢

World Reading Day | recommended books list of database classic books (free message at the end of the text)

ASP.NET Core实现JWT授权与认证(1.理论篇)

L2-005 集合相似度 (25 分)(set+容斥)

中商惠⺠交易中台架构演进:对 Apache ShardingSphere 的应⽤

Sentinelsat package introduction

Offline RL Series 4: analysis of the influence of sample complexity on model convergence

Hospital inpatient management information system (HIMS) developed based on SSM - graduation design - with source code

webrtc入门:2.使用getDisplayMedia获取屏幕桌面流

The simpler the Oracle database machine is, the more reliable it is. Oracle buried the "colored egg" 11 years ago

Analyze the future development direction of GPU
随机推荐
把数组字典写入csv格式
【C语言实现通讯录】一文带你遍历C语言重难点
【sql】SQL19 查找所有员工的last_name和first_name以及对应的dept_name
【MySQL】对JSON类型字段数据进行提取和查询
一个猜数字的小游戏
Scala安装和开发环境配置教程
Analyze the future development direction of GPU
路由基础之控制RIP路由的发布及路由引入
中商惠⺠交易中台架构演进:对 Apache ShardingSphere 的应⽤
【Flutter 专题】89 图解基本 Overlay 悬浮新手引导 #yyds干货盘点#
分享 Map 对象和普通对象的 7 个区别
Wechat applet to uniapp
leaflet军事标绘-突击方向修改(leaflet篇.90)
NoSuchBeanDefinitionException - not resolved currently
Yyds dry goods inventory a common error in a web crawler
The basic software products of xinghuan science and technology have been fully implemented and blossomed, bringing "Star" momentum to the digital transformation of enterprises
星汉未来成为FinOps产业推进方阵共建单位
Using lazy deletion and scheduled deletion to realize expired localstorage cache
关于 winform GridView 的操作
Kubernetes详解(二)——Kubernetes结构与资源对象