2022-05-26 10:06:25 -05:00
---
aliases:
2022-12-09 10:36:04 -06:00
- ../../installation/kubernetes/
2022-05-26 10:06:25 -05:00
description: Guide for deploying Grafana on Kubernetes
2023-06-19 10:27:40 -05:00
menuTitle: Grafana on Kubernetes
2022-05-26 10:06:25 -05:00
title: Deploy Grafana on Kubernetes
2023-06-19 10:27:40 -05:00
weight: 500
2022-05-26 10:06:25 -05:00
---
2021-03-25 21:09:05 -05:00
2022-07-28 13:37:07 -05:00
# Deploy Grafana on Kubernetes
2021-03-25 21:09:05 -05:00
2021-08-06 08:52:36 -05:00
This page explains how to install and run Grafana on Kubernetes (K8S). It uses Kubernetes manifests for the setup. If you prefer Helm, refer to the [Grafana Helm community charts ](https://github.com/grafana/helm-charts ).
2021-03-25 21:09:05 -05:00
2022-12-09 17:04:24 -06:00
## Deploy Grafana OSS on Kubernetes
2021-03-25 21:09:05 -05:00
2022-07-28 13:37:07 -05:00
This section explains how to install Grafana using Kubernetes.
If you are interested in the Grafana Enterprise version of this information, see [Deploy Grafana Enterprise on Kubernetes ](#deploy-grafana-enterprise-on-kubernetes ).
2021-08-06 08:52:36 -05:00
2022-07-28 13:37:07 -05:00
### Create a Grafana Kubernetes manifest
1. Create a file called `grafana.yaml` .
1. Copy and paste the following contents and save the file.
2021-03-25 21:09:05 -05:00
```yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
2021-04-13 09:03:15 -05:00
name: grafana-pvc
2021-03-25 21:09:05 -05:00
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:
2021-04-13 09:03:15 -05:00
securityContext:
fsGroup: 472
supplementalGroups:
2021-08-06 08:52:36 -05:00
- 0
2021-03-25 21:09:05 -05:00
containers:
2021-04-13 09:03:15 -05:00
- name: grafana
2022-09-15 14:46:13 -05:00
image: grafana/grafana:9.1.0
2021-03-25 21:09:05 -05:00
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
2021-04-13 09:03:15 -05:00
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 3000
2021-08-06 08:52:36 -05:00
timeoutSeconds: 1
2021-03-25 21:09:05 -05:00
resources:
requests:
2021-04-13 09:03:15 -05:00
cpu: 250m
memory: 750Mi
2021-03-25 21:09:05 -05:00
volumeMounts:
- mountPath: /var/lib/grafana
2021-04-13 09:03:15 -05:00
name: grafana-pv
2021-03-25 21:09:05 -05:00
volumes:
2021-04-13 09:03:15 -05:00
- name: grafana-pv
2021-03-25 21:09:05 -05:00
persistentVolumeClaim:
2021-04-13 09:03:15 -05:00
claimName: grafana-pvc
2021-03-25 21:09:05 -05:00
---
apiVersion: v1
kind: Service
metadata:
name: grafana
spec:
ports:
- port: 3000
protocol: TCP
targetPort: http-grafana
selector:
app: grafana
sessionAffinity: None
type: LoadBalancer
```
2022-07-28 13:37:07 -05:00
### Send the manifest to the Kubernetes API server
2021-03-25 21:09:05 -05:00
2021-08-06 08:52:36 -05:00
1. Run the following command:
`kubectl apply -f grafana.yaml`
2021-03-25 21:09:05 -05:00
1. Check that it worked by running the following:
2021-08-06 08:52:36 -05:00
`kubectl port-forward service/grafana 3000:3000`
2021-03-25 21:09:05 -05:00
2021-08-06 08:52:36 -05:00
1. Navigate to `localhost:3000` in your browser. You should see a Grafana login page.
2021-03-25 21:09:05 -05:00
1. Use `admin` for both the username and password to login.
## Deploy Grafana Enterprise on Kubernetes
2021-08-06 08:52:36 -05:00
2022-07-28 13:37:07 -05:00
The process for deploying Grafana Enterprise is almost identical to the preceding process, except for additional steps that are required for adding your license file.
2021-03-25 21:09:05 -05:00
### Obtain Grafana Enterprise license
2021-08-06 08:52:36 -05:00
2022-07-28 13:37:07 -05:00
To run Grafana Enterprise, you need a valid license.
2023-05-18 09:50:20 -05:00
To obtain a license, [contact a Grafana Labs representative ](/contact?about=grafana-enterprise ).
2022-07-28 13:37:07 -05:00
This topic assumes that you have a valid license in a `license.jwt` file.
Associate your license with a URL that you can use later in the topic.
2021-03-25 21:09:05 -05:00
2022-07-28 13:37:07 -05:00
### Create license secret
2021-08-06 08:52:36 -05:00
2021-03-25 21:09:05 -05:00
Create a Kubernetes secret from your license file using the following command:
2021-08-06 08:52:36 -05:00
2021-03-25 21:09:05 -05:00
```bash
kubectl create secret generic ge-license --from-file=/path/to/your/license.jwt
```
### Create Grafana Enterprise configuration
2021-08-06 08:52:36 -05:00
Create a Grafana configuration file with the name `grafana.ini` . Then paste the content below.
2023-05-22 15:45:28 -05:00
{{% admonition type="note" %}}
You will have to update the `root_url` field to the url associated with the license you were given.
{{% /admonition %}}
2021-08-06 08:52:36 -05:00
2021-03-25 21:09:05 -05:00
```yaml
[enterprise]
license_path = /etc/grafana/license/license.jwt
[server]
root_url =/your/license/root/url
```
2022-07-28 13:37:07 -05:00
### Create Configmap for Grafana Enterprise configuration
2021-08-06 08:52:36 -05:00
2021-03-25 21:09:05 -05:00
Create a Kubernetes Configmap from your `grafana.ini` file with the following command:
2021-08-06 08:52:36 -05:00
2021-03-25 21:09:05 -05:00
```bash
2022-07-28 13:37:07 -05:00
kubectl create configmap ge-config --from-file=/path/to/your/grafana.ini
2021-03-25 21:09:05 -05:00
```
2021-08-06 08:52:36 -05:00
2021-03-25 21:09:05 -05:00
### Create Grafana Enterprise Kubernetes manifest
2021-08-06 08:52:36 -05:00
2022-07-28 13:37:07 -05:00
Create a `grafana.yaml` file, and copy-and-paste the following content into it.
The YAML that follows is identical to the one for a Grafana installation, except for the additional references to the Configmap that contains your Grafana configuration file and the secret that has your license.
2021-03-25 21:09:05 -05:00
```yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
2022-07-28 13:37:07 -05:00
name: grafana-pvc
2021-03-25 21:09:05 -05:00
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:
2022-07-28 13:37:07 -05:00
securityContext:
fsGroup: 472
supplementalGroups:
- 0
2021-03-25 21:09:05 -05:00
containers:
- image: grafana/grafana-enterprise:latest
imagePullPolicy: IfNotPresent
name: grafana
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
resources:
limits:
memory: 4Gi
requests:
cpu: 100m
memory: 2Gi
volumeMounts:
- mountPath: /var/lib/grafana
2022-07-28 13:37:07 -05:00
name: grafana-pv
2021-03-25 21:09:05 -05:00
- mountPath: /etc/grafana
name: ge-config
- mountPath: /etc/grafana/license
name: ge-license
volumes:
2022-07-28 13:37:07 -05:00
- name: grafana-pv
2021-03-25 21:09:05 -05:00
persistentVolumeClaim:
2022-07-28 13:37:07 -05:00
claimName: grafana-pvc
2021-03-25 21:09:05 -05:00
- name: ge-config
configMap:
name: ge-config
- name: ge-license
secret:
secretName: ge-license
---
apiVersion: v1
kind: Service
metadata:
name: grafana
spec:
ports:
- port: 3000
protocol: TCP
targetPort: http-grafana
selector:
app: grafana
sessionAffinity: None
type: LoadBalancer
```
2021-08-06 08:52:36 -05:00
2023-05-22 15:45:28 -05:00
{{% admonition type="caution" %}}
If you use `LoadBalancer` in the Service and depending on your cloud platform and network configuration, doing so might expose your Grafana instance to the Internet. To eliminate this risk, use `ClusterIP` to restrict access from within the cluster Grafana is deployed to.
{{% /admonition %}}
2022-07-28 13:37:07 -05:00
2021-03-25 21:09:05 -05:00
1. Send manifest to Kubernetes API Server
2021-08-06 08:52:36 -05:00
`kubectl apply -f grafana.yaml`
2021-03-25 21:09:05 -05:00
1. Check that it worked by running the following:
2021-08-06 08:52:36 -05:00
`kubectl port-forward service/grafana 3000:3000`
2021-03-25 21:09:05 -05:00
2021-08-06 08:52:36 -05:00
1. Navigate to `localhost:3000` in your browser. You should see the Grafana login page.
2021-03-25 21:09:05 -05:00
1. Use `admin` for both the username and password to login.
2021-08-06 08:52:36 -05:00
If it worked, you should see `Enterprise (Licensed)` at the bottom of the page.