Monitor PXB clusters
This topic describes how you can monitor your Portworx Backup clusters with Prometheus and Grafana. This section is exclusively for the users who want to use external Prometheus and Grafana for extensive monitoring data of PXB clusters.
If you are referring to this topic, opt out of using PXB Prometheus stack for monitoring.
Configure Service Monitor
If Grafana already exists in the cluster where PXB is deployed, then you just have to configure service monitor to monitor PXB clusters. Apply the following spec in <pxb-deployed-namespace> for extensive monitoring:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
name: px-backup-sm
name: px-backup-sm
namespace: <pxb-deployed-namespace>
spec:
endpoints:
- metricRelabelings:
- action: labeldrop
regex: (instance|pod)
- action: drop
regex: process_.*
sourceLabels:
- __name__
- action: drop
regex: go_.*
sourceLabels:
- __name__
- action: drop
regex: grpc_.*
sourceLabels:
- __name__
port: rest-api
targetPort: 10001
namespaceSelector:
any: true
selector:
matchLabels:
app: px-backup
Prerequisites
- A Portworx Backup cluster
- Environment required to install Prometheus and Grafana
- 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. If no, execute the following steps.
kubectl apply -f - <<'_EOF'---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: prometheus-operatornamespace: <pxb-deployed-namespace>roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: prometheus-operatorsubjects:- kind: ServiceAccountname: prometheus-operatornamespace: <pxb-deployed-namespace>---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: prometheus-operatornamespace: <pxb-deployed-namespace>rules:- 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", "delete"]- apiGroups: [""]resources:- nodesverbs: ["list", "watch"]- apiGroups: [""]resources:- namespacesverbs: ["list", "watch", "get"]---apiVersion: v1kind: ServiceAccountmetadata:name: prometheus-operatornamespace: <pxb-deployed-namespace>---apiVersion: apps/v1kind: Deploymentmetadata:labels:k8s-app: prometheus-operatorname: prometheus-operatornamespace: <pxb-deployed-namespace>spec: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-prometheusnamespace: <pxb-deployed-namespace>rules:- 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-prometheusnamespace: <pxb-deployed-namespace>roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: px-backup-prometheussubjects:- kind: ServiceAccountname: px-backup-prometheusnamespace: <pxb-deployed-namespace>---apiVersion: v1kind: Servicemetadata:name: px-backup-prometheusnamespace: <pxb-deployed-namespace>spec:type: ClusterIPports:- name: webport: 9090protocol: TCPtargetPort: 9090selector:prometheus: px-backup-prometheus---apiVersion: v1kind: ServiceAccountmetadata:name: px-backup-prometheusnamespace: <pxb-deployed-namespace> -
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: <pxb-deployed-namespace>name: 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: <pxb-deployed-namespace>spec: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: <pxb-deployed-namespace>annotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-dashboardnamespace: <pxb-deployed-namespace>annotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-source-confignamespace: <pxb-deployed-namespace>annotations:volume.beta.kubernetes.io/storage-class: px-grafana-scspec:accessModes:- ReadWriteOnceresources:requests:storage: 1Gi---kind: PersistentVolumeClaimapiVersion: v1metadata:name: grafana-extensionsnamespace: <pxb-deployed-namespace>annotations: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: grafananamespace: <pxb-deployed-namespace>labels:app: grafanaspec:type: ClusterIPports:- port: 3000selector:app: grafana---apiVersion: apps/v1kind: Deploymentmetadata:name: grafananamespace: <pxb-deployed-namespace>labels: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: <pxb-deployed-namespace>annotations: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.