Kube-Prometheus监控主机和中间件(一)
一、背景简介
云原生技术是近年来发展迅速的一个领域,云原生应用程序具有弹性伸缩、持续交付、可观察性、安全性和资源利用率等优势,有助于企业更好地适应市场和竞争环境。随着云计算和容器化技术的不断成熟,它的发展趋势也越来越明显。
随着公司业务发展及技术架构的演进,云原生技术在公司新的项目中得到应用。但是使用云原生技术后,自研的监控平台成为业务发展的一个限制,如何解决监控问题,成为一个迫切的问题。
二、技术原理分析
三、命名空间及权限
命名空间
kubectl create namespace monitoring
# 执行结果:namespace/monitoring created
配置角色和权限
monitoring-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: prometheus-k8s
namespace: mos-monitoring
rules:
- apiGroups: [""]
resources:
- services
- endpoints
- pods
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- ingresses
verbs:
- get
- list
- watch
monitoring-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: prometheus-k8s
namespace: mos-monitoring
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: prometheus-k8s
subjects:
- kind: ServiceAccount
name: prometheus-k8s
namespace: monitoring
三、实施步骤
为了区分不同环境的监控数据,中间件监控在Service添加了自定义标签“platform: env”,ServiceMonitor通过targetLabels配置项将自定义标签添加到监控指标,后续可以根据该标签对监控数据进行隔离。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 逐光の博客!
评论