%%
date:: [[2021-09-01]], [[2023-06-11]]
parent::
%%
# [[Installing Grafana on Kubernetes]]
You can install [[Grafana]] on [[Kubernetes]] by using [[Helm for Kubernetes]] or by creating a manifest manually.
### Using Helm
This method requires the installation of [[Helm for Kubernetes]].
#### Add the Grafana Helm Chart
`helm repo add grafana https://grafana.github.io/helm-charts`
#### Install Grafana
`helm install grafana grafana/grafana`
#### Get access to the Grafana UI
##### Verify the port that Grafana is running on
`kubectl get pods` to get the name of the Grafana pod.
`kubectl logs grafana-76c678f75d-57tgt` to view the logs of the Grafana pod.
Look in the logs for something like this: `t=2021-07-21T18:22:27+0000 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3000 protocol=http subUrl= socket=`
<!--ID: 1631100131523-->
In the example above, the port number is 3000.
#### [[kubectl#Port forwarding|Forward the port]]
`kubectl port-forward deployment/grafana 3000`
This will allow you to access the Grafana UI on `localhost:3000`
#### Log into the UI
Grafana doesn't have a default password, and it's generated for every installation. To find yours, run this command:
`kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo`
Log into Grafana with the user `admin` and the password that you got above.
### Using manifests
#### Create the manifest
Create a file called `grafana.yaml` with the contents below:
```yaml
---
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:7.5.2
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
```
[^grafanadocs]
#### Apply the manifest file
Use [[kubectl]] to apply the configurations specified in the manifest file:
`kubectl apply -f grafana.yaml`
#### [[kubectl#Port forwarding|Forward the port]]
`kubectl port-forward service/grafana 3000:3000`
#### Log into the UI
Grafana should be accessible via `localhost:3000`, using `admin` as both the username and password.
[^grafanadocs]: Grafana Labs. _Deploy Grafana on Kubernetes_. Retrieved from https://grafana.com/docs/grafana/latest/installation/kubernetes/ .