Configure Prometheus and Grafana
This document shows how you can monitor your Portworx Backup cluster with Prometheus and Grafana.
Prerequisites
- A Portworx Backup cluster
- You must have
kubectlaccess to your Portworx Backup cluster
Below topic explains the deployment of monitoring stack in Portworx Backup namespace. If Portworx Backup is deployed in a different namespace, please ensure to modify the namespace wherever required.
Install and configure Prometheus
-
(Optional) Enter the following combined spec and
kubectlcommand to install the Prometheus Operator:Skip this step if you have not configured your own Prometheus stack in Portworx Backup version 2.7.0 and above
kubectl apply -f - <<'_EOF'---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: prometheus-operatornamespace: px-backuproleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: prometheus-operatorsubjects:- kind: ServiceAccountname: prometheus-operatornamespace: px-backup---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: prometheus-operatornamespace: px-backuprules:- apiGroups:- extensionsresources:- thirdpartyresourcesverbs: ["*"]- apiGroups:- apiextensions.k8s.ioresources:- customresourcedefinitionsverbs: ["*"]- apiGroups:- monitoring.coreos.comresources:- alertmanagers- prometheuses- prometheuses/finalizers- servicemonitors- prometheusrules- podmonitors- thanosrulers- alertmanagerconfigs- probesverbs: ["*"]- apiGroups:- appsresources:- statefulsetsverbs: ["*"]- apiGroups: [""]resources:- configmaps- secretsverbs: ["*"]- apiGroups: [""]resources:- podsverbs: ["list", "delete"]- apiGroups: [""]resources:- services- endpointsverbs: ["get", "create", "update"]- apiGroups: [""]resources:- nodesverbs: ["list", "watch"]- apiGroups: [""]resources:- namespacesverbs: ["list", "watch", "get"]---apiVersion: v1kind: ServiceAccountmetadata:name: prometheus-operatornamespace: px-backup---apiVersion: apps/v1kind: Deploymentmetadata:labels:k8s-app: prometheus-operatorname: prometheus-operatornamespace: px-backupspec:selector:matchLabels:k8s-app: prometheus-operatorreplicas: 1template:metadata:labels:k8s-app: prometheus-operatorspec:containers:- args:- --kubelet-service=kube-system/kubelet- --prometheus-config-reloader=docker.io/portworx/prometheus-config-reloader:v0.56.3- --namespaces=px-backupname: prometheus-operatorimage: docker.io/portworx/prometheus-operator:v0.56.3ports:- containerPort: 8080name: httpresources:limits:cpu: 200mmemory: 100Mirequests:cpu: 100mmemory: 50MisecurityContext:runAsNonRoot: truerunAsUser: 65534serviceAccountName: prometheus-operator -
To grant Prometheus access to the metrics API, create the
ClusterRole,ClusterRoleBinding,Service, andServiceAccountKubernetes objects:kubectl apply -f - <<'_EOF'---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: px-backup-prometheusrules:- apiGroups:- ""resources:- nodes- services- endpoints- podsverbs:- get- list- watch- apiGroups:- ""resources:- configmapsverbs:- get- nonResourceURLs:- /metrics- /federateverbs:- get---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: px-backup-prometheusroleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: px-backup-prometheussubjects:- kind: ServiceAccountname: px-backup-prometheusnamespace: px-backup---apiVersion: v1kind: Servicemetadata:name: px-backup-prometheusnamespace: px-backupspec:type: ClusterIPports:- name: webport: 9090protocol: TCPtargetPort: 9090selector:prometheus: px-backup-prometheus---apiVersion: v1kind: ServiceAccountmetadata:name: px-backup-prometheusnamespace: px-backup -
To specify the monitoring rules for Portworx Backup, create a
ServiceMonitorobject by entering the following combined spec andkubectlcommand:kubectl apply -f - <<'_EOF'---apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata:namespace: px-backupname: px-backup-prometheus-smlabels:name: px-backup-prometheus-smspec:selector:matchLabels:app: px-backupnamespaceSelector:any: trueendpoints:- port: rest-apitargetPort: 10001 -
Apply Prometheus specs for Portworx Backup metrics:
kubectl apply -f - <<'_EOF'---apiVersion: monitoring.coreos.com/v1kind: Prometheusmetadata:name: px-backup-prometheusnamespace: px-backupspec:replicas: 2logLevel: debugserviceAccountName: px-backup-prometheusserviceMonitorSelector:matchLabels:name: px-backup-prometheus-sm
Install and configure Grafana
-
Create a storage class for Grafana and persistent volumes with the grafana-data, grafana-dashboard, grafana-source-config, and grafana-extensions names:
kubectl apply -f - <<'_EOF'---kind: StorageClassapiVersion: storage.k8s.io/v1metadata:name: px-grafana-scprovisioner: kubernetes.io/portworx-volumeparameters:repl: "3"priority_io: "high"allowVolumeExpansion: true---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-datanamespace: px-backupannotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-dashboardnamespace: px-backupannotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-source-confignamespace: px-backupannotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-extensionsnamespace: px-backupannotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1GinoteIn this storage class:
- The
provisionerparameter is set tokubernetes.io/portworx-volume. For details about the Portworx-specific parameters, refer to the Portworx Volume section of the Kubernetes website. - Three replicas of each volume will be created.
- The
-
Enter the following command to install Grafana:
noteIf your cluster is on a cloud provider, then follow the instructions in Step 3 to export it to a node port or load balancer.
kubectl apply -n px-backup -f - <<'_EOF'---apiVersion: v1kind: Servicemetadata:name: grafanalabels:app: grafanaspec:type: ClusterIPports:- port: 3000selector:app: grafana---apiVersion: apps/v1kind: Deploymentmetadata:name: grafanalabels:app: grafanaspec:replicas: 1selector:matchLabels:app: grafanatemplate:metadata:labels:app: grafanaspec:securityContext:fsGroup: 2000containers:- image: docker.io/portworx/grafana:7.5.16name: grafanaimagePullPolicy: Alwaysresources:limits:cpu: 100mmemory: 100Mirequests:cpu: 100mmemory: 100MireadinessProbe:httpGet:path: /loginport: 3000volumeMounts:- name: grafanamountPath: /etc/grafana/provisioning/dashboardreadOnly: false- name: grafana-dashmountPath: /var/lib/grafana/dashboardsreadOnly: false- name: grafana-source-cfgmountPath: /etc/grafana/provisioning/datasourcesreadOnly: false- name: grafana-pluginsmountPath: /var/lib/grafana/pluginsreadOnly: falsevolumes:- name: grafanapersistentVolumeClaim:claimName: grafana-data- name: grafana-dashpersistentVolumeClaim:claimName: grafana-dashboard- name: grafana-source-cfgpersistentVolumeClaim:claimName: grafana-source-config- name: grafana-pluginspersistentVolumeClaim:claimName: grafana-extensionsnoteIn this deployment, the
volumessection references the PVCs you created in the previous step. -
Enter the following
kubectl port-forwardcommand to forward all connections made tolocalhost:3000tosvc/grafana:3000:kubectl port-forward svc/grafana --namespace px-backup --address 0.0.0.0 3000Alternatively, if your cluster is on a cloud provider, perform one of the following to export to the nodeport or loadbalancer:
-
To export to the nodeport, navigate to Install and configure Grafana, change the following parameter in Step 2:
type: NodePortnoteThe cluster node must be accessible using an external IP.
-
To export to the loadbalancer, create an ingress role:
apiVersion: extensions/v1beta1kind: Ingressmetadata:name: guestbook2namespace: px-backupannotations:kubernetes.io/ingress.class: azure/application-gatewayspec:rules:- http:paths:- backend:serviceName: px-backup-prometheusservicePort: 9090
-
-
Follow the instructions in Prometheus documentation to create a Prometheus data source named
px-backup. Please ensure to replace the HTTP URL fromhttp://localhost:9090/tohttp://prometheus-operated:9090/. -
Follow the instructions in Grafana documentation to import the Portworx Backup dashboard JSON file.