Deploy Grafana for visualization

Install the Grafana Operator and create a Grafana instance connected to Prometheus so that you can build dashboards that display Red Hat Edge Manager service and device metrics.

Before you begin

  • A Red Hat OpenShift Container Platform cluster version 4.19 or later and cluster-admin permissions.
  • The monitoring stack is deployed per Deploying the monitoring stack.
  • The OpenShift CLI (oc) installed and authenticated to the cluster.

About this task

Important

The following steps install the Grafana Operator from the community-operators catalog. Community Operators are not supported by Red Hat. Confirm compliance with your cluster policy before you subscribe.

Procedure

  1. Install the Grafana Operator:
    $ oc create -f - <<EOF
    apiVersion: operators.coreos.com/v1alpha1
    kind: Subscription
    metadata:
      name: grafana-operator
      namespace: openshift-operators
    spec:
      channel: v5
      name: grafana-operator
      source: community-operators
      sourceNamespace: openshift-marketplace
    EOF
  2. Wait until the operator ClusterServiceVersion reports phase Succeeded:
    $ oc wait --for=jsonpath='{.status.phase}'=Succeeded \
      csv -l operators.coreos.com/grafana-operator.openshift-operators \
      -n openshift-operators --timeout=300s
  3. Create a NetworkPolicy so that the Grafana Operator in openshift-operators and the cluster ingress router can reach the Grafana pods. Without the ingress rule, traffic from openshift-ingress router pods is denied if your namespace applies default-deny-style policies.
    $ oc create -f - <<EOF
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: allow-grafana-operator-and-ingress
      namespace: <project_name>
    spec:
      podSelector:
        matchLabels:
          app.kubernetes.io/name: grafana
      policyTypes:
      - Ingress
      ingress:
      - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: openshift-operators
        ports:
          - protocol: TCP
            port: 3000
      - from:
        - namespaceSelector:
            matchLabels:
              network.openshift.io/policy-group: ingress
        ports:
          - protocol: TCP
            port: 3000
    EOF
  4. Create a Grafana instance in <project_name>:
    $ oc create -f - <<EOF
    apiVersion: grafana.integreatly.org/v1beta1
    kind: Grafana
    metadata:
      name: flightctl-grafana
      namespace: <project_name>
      labels:
        dashboards: flightctl
    spec:
      config:
        log:
          mode: console
        security:
          admin_user: admin
          admin_password: admin
      deployment:
        spec:
          template:
            metadata:
              labels:
                app.kubernetes.io/name: grafana
    EOF
  5. Create a GrafanaDatasource that points to the Prometheus service:
    $ oc create -f - <<EOF
    apiVersion: grafana.integreatly.org/v1beta1
    kind: GrafanaDatasource
    metadata:
      name: flightctl-monitoring
      namespace: <project_name>
    spec:
      allowCrossNamespaceImport: false
      datasource:
        access: proxy
        isDefault: true
        jsonData:
          timeInterval: 5s
          tlsSkipVerify: true
        name: prometheus
        type: prometheus
        url: 'http://flightctl-monitoring-stack-prometheus.<project_name>.svc.cluster.local:9090'
      instanceSelector:
        matchLabels:
          dashboards: flightctl
    EOF

    Replace <project_name> in the url field with your actual namespace name (DNS label, without angle brackets).

  6. Create a Route to expose the Grafana service:
    $ oc create route edge flightctl-grafana-route \
      --service=flightctl-grafana-service \
      --port=grafana \
      -n <project_name>

Results

  • Obtain the Grafana URL:
    $ echo "https://$(oc get route flightctl-grafana-route -n <project_name> -o jsonpath='{.spec.host}')"
  • Open the URL in a web browser and sign in with the administrator user name admin and password admin. Warning

    Change the default Grafana administrator password before you use this deployment in production. The example password is suitable only for initial testing.