---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    name: monitor-network
  name: monitor-network
  namespace: network-metrics
spec:
  endpoints:
    - interval: 10s
      port: metrics
      honorLabels: true
  selector:
    matchLabels:
      service: network-metrics-service
  namespaceSelector:
    matchNames:
      - network-metrics
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/scrape: "true"
  labels:
    service: network-metrics-service
  name: network-metrics-service
  namespace: network-metrics
spec:
  selector:
    app: network-metrics-daemon
  clusterIP: None
  ports:
    - name: metrics
      port: 9091
      protocol: TCP
      targetPort: 9091
  type: ClusterIP
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: prometheus-k8s
  namespace: network-metrics
rules:
  - apiGroups:
      - ""
    resources:
      - services
      - endpoints
      - pods
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: prometheus-k8s
  namespace: network-metrics
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: prometheus-k8s
subjects:
  - kind: ServiceAccount
    name: prometheus-k8s
    namespace: monitoring
