1.service.yaml
可根据需要修改namespace和ip
apiVersion: v1
kind: Service
metadata:
name: service
namespace: example
labels:
k8s-app: unit
spec:
type: ClusterIP
clusterIP: None
ports:
- name: port
port: 8000
---
apiVersion: v1
kind: Endpoints
metadata:
name: service
namespace: example
labels:
k8s-app: unit
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: port
port: 8000
2.service-monitor.yaml
namespace及k8s-app需和service.yaml相对应
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: service
namespace: example
labels:
k8s-app: unit
spec:
jobLabel: k8s-app
endpoints:
- port: port
interval: 30s
scheme: http
selector:
matchLabels:
k8s-app: unit
namespaceSelector:
matchNames:
- example
依次执行,prometheus界面可以看到对应的监控信息。