Install Grafana in Kubernetes

Everton Araújo
2 min readJul 15, 2022

Hello, after a while without writing due to the rush of work. I’m doing my basic Grafana installation post on Kubernetes (K8S), it can be used: Docker desktop inside your machine with kubernetes, minikube, EKS, AKS and etc.

This version is the community (v9.0.2).

Create Grafana Kubernetes manifest

  1. Create a file called grafana.yaml, then paste the contents below.
---
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

Send manifest to Kubernetes API server

  1. Run the following command: kubectl apply -f grafana.yaml

2. Check that it worked by running the following: kubectl port-forward service/grafana 3000:3000

3. Navigate to localhost:3000 in your browser. You should see a Grafana login page.

4. Use admin for both the username and password to login.

5. One of the points I made in Yaml: change the Grafana image version to latest version.

Next time I will bring more information about Grafana.

--

--