抓取外部指标
具体配置示例如下:
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: monitor-kube-prometheus-st-prometheus
spec:
additionalScrapeConfigs:
- job_name: external
metrics_path: /metrics
static_configs:
- targets:
- <IP>:<PORT>
external name Service + ServiceMonitor
配置 Externalname Service:
apiVersion: v1
kind: Service
metadata:
name: gpu-metrics-svc
namespace: monitoring
labels:
k8s-app: gpu-metrics
spec:
type: ExternalName
externalName: <gpu-machine-ip>
clusterIP: ''
ports:
- name: metrics
port: 9100
protocol: TCP
targetPort: 9100
配置指向该 Service 的 ServiceMonitor:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: gpu-metrics-sm
labels:
k8s-app: gpu-metrics
prometheus: kube-prometheus
spec:
selector:
matchLabels:
k8s-app: gpu-metrics
namespaceSelector:
matchNames:
- monitoring
endpoints:
- port: metrics
interval: 10s
honorLabels: true
方案二
通过 Service + Endpoint 方式, 明确将外部服务映射为内部 Service
kind: Service
apiVersion: v1
metadata:
name: dev-nas-node-exporter
labels:
app: dev-nas-node-exporter
namespace: monitoring
spec:
type: ClusterIP
ports:
- name: metrics
port: 9100
protocol: TCP
targetPort: 9100
---
apiVersion: v1
kind: Endpoints
metadata:
name: dev-nas-node-exporter
labels:
app: dev-nas-node-exporter
namespace: monitoring
subsets:
- addresses:
- ip: 10.244.244.3
ports:
- name: metrics
port: 9100
protocol: TCP
再创建对应的 ServiceMonitor 即可: