title: “Openshift prometheus targets”
date: 2020-02-14T18:02:43
slug: openshift-prometheus-targets
Create Rolebinding for prometheus for scraping:
apiVersion: authorization.openshift.io/v1
kind: Role
metadata:
name: prometheus-k8s
namespace: emqx-openshift
rules:
- apiGroups:
- ""
attributeRestrictions: null
resources:
- endpoints
- nodes
- pods
- services
verbs:
- get
- list
- watch
---
apiVersion: authorization.openshift.io/v1
groupNames: null
kind: RoleBinding
metadata:
name: prometheus-k8s
namespace: emqx-openshift
roleRef:
name: prometheus-k8s
namespace: emqx-openshift
subjects:
- kind: ServiceAccount
name: prometheus-k8s
namespace: openshift-monitoring
userNames:
- system:serviceaccount:openshift-monitoring:prometheus-k8s
Create a Service Monitor
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
k8s-app: emqx-metrics
name: emqx-metrics
namespace: openshift-monitoring
spec:
endpoints:
- interval: 30s
port: metrics
scheme: http
targetPort: 9091
jobLabel: k8s-app
namespaceSelector:
matchNames:
- emqx-openshift
selector:
matchLabels:
k8s-app: emqx-metrics
Create a metrics Service
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2020-02-14T16:38:26Z"
labels:
k8s-app: emqx-metrics
name: emqx
namespace: emqx-openshift
resourceVersion: "810916"
selfLink: /api/v1/namespaces/emqx-openshift/services/emqx
uid: 6c740138-4f48-11ea-8568-fa163e8ef4af
spec:
clusterIP: None
ports:
- name: metrics
port: 9091
protocol: TCP
targetPort: 9091
selector:
deploymentconfig: emqx-openshift
sessionAffinity: None
type: ClusterIP
