Automatic Deployment of Dashboards on OpenShift

  • What Grafana version and what operating system are you using?
    8.1.x

  • What are you trying to achieve?
    I want to ensure that our dashboards are created/updated from Bitbucket Repo each time the Grafana instance Pod is deployed on OpenShift.

  • How are you trying to achieve it?
    I have a Bitbucket Repo with a Dockerfile with content “FROM grafana/grafana:latest” only. Additionally I have a directory “dashboards” that contains two JSON files with our dashboards. Using Mounts/Volumes in OpenShift template.yaml and according commands in Jankinsfile (see below) I pass those files to Grafana Pod.

  • What happened?
    The files of the dashboards can be found inside the pod but dashboards are not shown in Grafana.

  • What did you expect to happen?
    I expect to see the dashboards in Grafana and that those are created/updated when the Pod is deployed.

  • Can you copy/paste the configuration(s) that you are having problems with?

template.yaml

apiVersion: v1
kind: Template
metadata:
name: deployment-template
labels:
template: deployment-template
objects:

  • apiVersion: v1
    kind: DeploymentConfig
    metadata:
    labels:
    app: elan-grafana-instance
    name: elan-grafana-instance
    spec:
    replicas: ${{REPLICAS}}
    selector:
    app: elan-grafana-instance
    template:
    metadata:
    labels:
    category: vertriebsbank
    app: elan-grafana-instance
    np/ruv-elan: provider
    spec:
    containers:
    - name: elan-grafana-instance
    image: ${REGISTRY}/${NAMESPACE}/${APP}:${VERSION}
    imagePullPolicy: Always
    ports:
    - containerPort: 3000
    protocol: TCP
    resources:
    requests:
    memory: ${MEMORY_REQUEST}
    cpu: ${CPU_REQUEST}
    limits:
    memory: ${MEMORY_LIMIT}
    cpu: ${CPU_LIMIT}
    volumeMounts:
    - mountPath: /var/lib/grafana
    name: grafana-data
    - mountPath: /etc/grafana
    name: grafana-config-instance
    - mountPath: /etc/grafana/provisioning/datasources
    name: grafana-datasources-provision
    - mountPath: /etc/grafana/provisioning/dashboards
    name: grafana-dashboards-provision
    - mountPath: /grafana-dashboard-definitions/grafana-dashboards
    name: grafana-dashboards
    - mountPath: /etc/grafana/provisioning/notifiers
    name: grafana-notifiers-provision
    - mountPath: /etc/grafana/provisioning/plugins
    name: grafana-plugins-provision
    env:
    - name: APP_VERSION
    value: ‘${VERSION}’
    - name: SERVER_PORT
    value: ‘3000’
    - name: GF_SECURITY_ADMIN_USER
    value: elan
    - name: GF_SECURITY_ADMIN_PASSWORD
    value: elan
    - name: MY_POD_NAMESPACE
    valueFrom:
    fieldRef:
    fieldPath: metadata.namespace
    - name: POD_IP
    valueFrom:
    fieldRef:
    fieldPath: status.podIP
    volumes:
    - emptyDir: { }
    name: grafana-data
    - configMap:
    defaultMode: 420
    name: grafana-config-instance
    name: grafana-config-instance
    - name: grafana-datasources-provision
    secret:
    defaultMode: 420
    secretName: elan-grafana-datasources
    - configMap:
    defaultMode: 420
    name: grafana-dashboards-provision
    name: grafana-dashboards-provision
    - configMap:
    defaultMode: 420
    name: grafana-dashboards
    name: grafana-dashboards
    - configMap:
    defaultMode: 420
    name: grafana-notifiers-provision
    name: grafana-notifiers-provision
    - emptyDir: { }
    name: grafana-plugins-provision

  • apiVersion: v1
    kind: Service
    metadata:
    labels:
    app: elan-grafana-instance
    name: elan-grafana-instance
    spec:
    selector:
    app: elan-grafana-instance
    ports:
    - name: container
    protocol: TCP
    port: 3000
    targetPort: 3000

  • apiVersion: v1
    kind: Route
    metadata:
    labels:
    app: elan-grafana-instance
    name: elan-grafana-instance
    spec:
    port:
    targetPort: container
    tls:
    termination: edge
    to:
    kind: Service
    name: elan-grafana-instance

  • apiVersion: v1
    kind: ConfigMap
    metadata:
    labels:
    app: grafana-config-instance
    name: grafana-config-instance
    data:
    grafana.ini: |-
    [paths]
    data = /var/lib/grafana
    logs = /var/lib/grafana/logs
    plugins = /var/lib/grafana/plugins
    provisioning = /etc/grafana/provisioning
    [smtp]
    enabled = ${ALERTING_ENABLED}
    host = mailgateway.default.svc:25
    from_address = …
    skip_verify = true

  • apiVersion: v1
    kind: ConfigMap
    metadata:
    labels:
    app: grafana-notifiers-provision
    name: grafana-notifiers-provision
    data:
    notifiers.yaml: |-
    notifiers:
    - name: Developer Mail
    type: email
    uid: developermail
    org_id: 1
    is_default: true
    disable_resolve_message: true
    send_reminder: true
    frequency: 2h
    settings:
    singleEmail: true
    uploadImage: true
    addresses: …
    parameters:

  • name: NAMESPACE
    required: true

  • name: VERSION
    required: true

  • name: REGISTRY
    required: true

  • name: MONITOR_API_VERSION

  • name: CLUSTER

  • name: STAGE

  • name: APP
    displayName: Application Name
    description: The name of your application and of your image
    required: true
    value: elan-grafana-instance

  • name: REPLICAS
    displayName: Replicas.
    description: Replicas of the application to run.
    required: true

  • name: MEMORY_LIMIT
    displayName: Memory Limit
    value: “4Gi”

  • name: MEMORY_REQUEST
    displayName: Memory Request
    value: “200Mi”
    required: true

  • name: CPU_LIMIT
    displayName: CPU Limit
    value: “500m”

  • name: CPU_REQUEST
    displayName: CPU Request
    value: “10m”

  • name: ALERTING_ENABLED
    displayName: Alerting switch
    description: true for alerting enabled, false for alerting disabled
    value: “true”
    required: false

Part of Jenkinsfile

pipeline {

agent { label 'mvn11' }

environment {
    APP = 'elan-grafana-instance'
    RELEASE_NUMBER = 1
}

options {
    buildDiscarder(logRotator(numToKeepStr: '4'))
}

stages {
    stage('➁ Build') {
        steps {
            sh '''
               oc delete configmap elan-grafana-dashboards --ignore-not-found=true
               oc create configmap elan-grafana-dashboards --from-file=dashboards/
            '''
            buildDockerImage(semVer: true)
        }
    }
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No

  • Did you follow any online instructions? If so, what is the URL?
    Do not understand this question

Could anyone help me please?