Set up Grafana OSS with minikube

Grafana is a “is a multi-platform open source analytics and interactive visualization web application“. It can be used for data visualization and metrics monitoring, including infrastructure such as servers and containers.

To deploy Grafana using Kubernetes, you will need a host with Kubernetes installed or a cloud service to do it such as EKS or AKS. To keep things simple, in this case, I’ll use a Linux server with minikubectl installed. To install minikubectl on Linux, you can follow the official documentation. Keep in mind that minikube has several hardware requirements that could be a problem if you have limited resources. Before deploying Grafana, you should have your minikube cluster up and running. Once that’s done, if you already had kubectl installed you can just use the usual command (kubectl…) or you can use minikube kubectl instead.

Create the Granafa’s .yml file

First, create a directory with a file inside called grafana-oss.yml:

mkdir grafana-k8
cd grafana-k8
touch grafana-oss.yml

Now, inside the .yml file place the following content:

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
spec:
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      securityContext:
        fsGroup: 472
        supplementalGroups:
          - 0
      containers:
        - name: grafana
          image: grafana/grafana:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
              name: http-grafana
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /robots.txt
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 2
          livenessProbe:
            failureThreshold: 3
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: 3000
            timeoutSeconds: 1
          resources:
            requests:
              cpu: 250m
              memory: 750Mi
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-pv
      volumes:
        - name: grafana-pv
          persistentVolumeClaim:
            claimName: grafana-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: http-grafana
  selector:
    app: grafana
  sessionAffinity: None
  type: LoadBalancer

This file is available in the Grafana documentation. There’s several things to consider in that file. It uses the latest Grafana docker image available here with the port 3000.

To apply this .yml file, run the following command:

minikube kubectl apply -f grafana-oss.yml

To expose the port so the Grafana instance can be accessible, run:

minikube kubectl port-forward service/grafana 3000:3000

It may take a while to actually be accessible, keep that in mind if you see Connection Refused errors. After that, you should be able to see the Granafa’s GUI:

The default user is admin and the password is also admin. You should see a message to change the temporary password. After that, you will see the main page:

| Theme: UPortfolio