How to install grafana plugin in kubernetes?

Viewed 8806

I am deploying grafana(6.6.0) in kubernetes cluster(v1.15.2) and now I want to install Pie Chart plugin in grafana. When I am not in docker, I could use this command to install:

grafana-cli plugins install grafana-piechart-panel

But now I am in kubernetes cluster, I could login to the pod and run install command, but when the pod is destroyed and recreated the installing history is lost. What should I do to permanently install plugin in the kubernetes cluster grafana? I have tried to define in yaml like this:

"name": "grafana",
            "image": "grafana/grafana:6.6.0",
            "ports": [
              {
                "name": "http",
                "containerPort": 3000,
                "protocol": "TCP"
              }
            ],
            "env": [
              {
                "name": "GF_INSTALL_PLUGINS",
                "value": "grafana-piechart-panel"
              }
            ],

and not works for me.

4 Answers

In recent versions of Grafana helm chart, plugins list can be passed as list in values.yaml

## Pass the plugins you want installed as a list.
##
plugins: []
  # - digrich-bubblechart-panel
  # - grafana-clock-panel

Use a persistent disk and mount /var/lib/grafana. Plugins are present in /var/lib/grafana/plugins. After containers restarts the data will persist.

Here is what worked for me when deploying Grafana 7.x and plugins with persistent storage.

apiVersion: v1
kind: ConfigMap
metadata:
        name: grafana-config
        labels:
                apps: grafana
data:
        GF_INSTALL_PLUGINS: grafana-piechart-panel,grafana-clock-panel, redis-datasource, doitintl-bigquery-datasource, grafana-simple-json-datasource, ae3e-plotly-panel,redis-app
---
apiVersion: v1
kind: PersistentVolume
metadata:
        name: grafana-pv
        labels:
                type: local
                app: grafana
spec:
        storageClassName: standard
        capacity:
                storage: 5Gi
        accessModes:
                - ReadWriteMany
        hostPath:
                path: "/mnt/grafana"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
        name: grafana-pv-claim
        labels:
                apps: grafana
spec:
        storageClassName: standard
        accessModes:
                - ReadWriteMany
        resources:
                requests:
                        storage: 5Gi
---
apiVersion: v1
kind: Service
metadata:
        name: grafana
        labels:
                apps: grafana
spec:
        type: NodePort
        ports:
                - nodePort: 30081
                  targetPort: 3000
                  port: 3000
        selector:
                app: grafana
---
apiVersion: apps/v1
kind: Deployment
metadata:
        name: grafana-deployment
        labels:
                app: grafana
spec:
        replicas: 1
        selector:
                matchLabels:
                        app: grafana
        template:
                metadata:
                        labels:
                                app: grafana
                spec:
                        containers:
                                - name: grafana
                                  image: docker.io/grafana/grafana:7.4.0
                                  envFrom:
                                          - configMapRef:
                                                  name: grafana-config
                                  imagePullPolicy: IfNotPresent
                                  volumeMounts:
                                          - mountPath: /var/lib/grafana
                                            name: grafana
                                  ports:
                                          - containerPort: 3000
                        securityContext:
                                fsGroup: 472
                                runAsUser: 0
                        volumes:
                                - name: grafana
                                  persistentVolumeClaim:
                                          claimName: grafana-pv-claim
                                        
Related