目前公司在用的Prometheus是安裝在k8s集群中,安裝方式類似如下如下鏈接:
https://blog.csdn.net/zhangshaohuas/article/details/107681209
安裝于k8s集群中的Prometheus如果要監(jiān)控k8s集群外的服務或者服務器斑唬,那么需要用到k8s的endpoint資源市埋,將外部服務映射為集群的內(nèi)部服務,然后進行訪問通信恕刘。
Kubernetes-服務連接和暴露(endpoints)(二十) (juejin.cn)
創(chuàng)建好能連接外部資源的endponit 后缤谎,再創(chuàng)建service 和serviceMonitor資源 就能監(jiān)控到一個外部服務,如下是范例yaml文件:
監(jiān)控外部linux主機的serviceMonitor\service\endpoint的yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: linux-metrics-sm
namespace: monitoring
labels:
prometheus: k8s
spec:
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
k8s-app: linux-metrics
endpoints:
- port: metrics
interval: 10s
---
apiVersion: v1
kind: Service
metadata:
name: linux-metrics
namespace: monitoring
labels:
k8s-app: linux-metrics
spec:
type: ExternalName
externalName: 192.168.0.20
clusterIP: ""
ports:
- name: metrics
port: 9100
protocol: TCP
targetPort: 9100
---
apiVersion: v1
kind: Endpoints
metadata:
name: linux-metrics #name與service的name一致
namespace: monitoring
labels:
k8s-app: linux-metrics
subsets:
- addresses:
- ip: 192.168.0.20
ports:
- name: metrics
port: 9100
protocol: TCP