Deploy Grafana on Kubernetes

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.

If you are interested in Grafana Enterprise (not Grafana OS), jump to Deploy Grafana Enterprise on Kubernetes section.

Create Grafana Kubernetes manifest

  1. Create a file called grafana.yaml, then paste the contents below.
  1. ---
  2. apiVersion: v1
  3. kind: PersistentVolumeClaim
  4. metadata:
  5. name: grafana-pvc
  6. spec:
  7. accessModes:
  8. - ReadWriteOnce
  9. resources:
  10. requests:
  11. storage: 1Gi
  12. ---
  13. apiVersion: apps/v1
  14. kind: Deployment
  15. metadata:
  16. labels:
  17. app: grafana
  18. name: grafana
  19. spec:
  20. selector:
  21. matchLabels:
  22. app: grafana
  23. template:
  24. metadata:
  25. labels:
  26. app: grafana
  27. spec:
  28. securityContext:
  29. fsGroup: 472
  30. supplementalGroups:
  31. - 0
  32. containers:
  33. - name: grafana
  34. image: grafana/grafana:8.4.4
  35. imagePullPolicy: IfNotPresent
  36. ports:
  37. - containerPort: 3000
  38. name: http-grafana
  39. protocol: TCP
  40. readinessProbe:
  41. failureThreshold: 3
  42. httpGet:
  43. path: /robots.txt
  44. port: 3000
  45. scheme: HTTP
  46. initialDelaySeconds: 10
  47. periodSeconds: 30
  48. successThreshold: 1
  49. timeoutSeconds: 2
  50. livenessProbe:
  51. failureThreshold: 3
  52. initialDelaySeconds: 30
  53. periodSeconds: 10
  54. successThreshold: 1
  55. tcpSocket:
  56. port: 3000
  57. timeoutSeconds: 1
  58. resources:
  59. requests:
  60. cpu: 250m
  61. memory: 750Mi
  62. volumeMounts:
  63. - mountPath: /var/lib/grafana
  64. name: grafana-pv
  65. volumes:
  66. - name: grafana-pv
  67. persistentVolumeClaim:
  68. claimName: grafana-pvc
  69. ---
  70. apiVersion: v1
  71. kind: Service
  72. metadata:
  73. name: grafana
  74. spec:
  75. ports:
  76. - port: 3000
  77. protocol: TCP
  78. targetPort: http-grafana
  79. selector:
  80. app: grafana
  81. sessionAffinity: None
  82. 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.

Deploy Grafana Enterprise on Kubernetes

The process for deploying Grafana Enterprise is almost identical to the process above, except for some extra steps required to add in your license file. They are described in the following sections.

Obtain Grafana Enterprise license

To run Grafana Enterprise, you need a valid license. Contact a Grafana Labs representative to obtain the license. This topic assumes that you already have done this and have a license.jwt file. Your license should also be associated with a URL, which we will use later in the topic.

Create License Secret

Create a Kubernetes secret from your license file using the following command:

  1. kubectl create secret generic ge-license --from-file=/path/to/your/license.jwt

Create Grafana Enterprise configuration

Create a Grafana configuration file with the name grafana.ini. Then paste the content below.

Note: You will have to update the root_url field to the url associated with the license you were given.

  1. [enterprise]
  2. license_path = /etc/grafana/license/license.jwt
  3. [server]
  4. root_url =/your/license/root/url

Create Configmap for Grafana Enterprise Config

Create a Kubernetes Configmap from your grafana.ini file with the following command:

  1. kubectl create configmap ge-config --from-file=/path/to/your/config.ini

Create Grafana Enterprise Kubernetes manifest

Create a grafana.yaml file, then paste the content below. This YAML is identical to the one for Grafana OS install except for the additional references to the Configmap which has your Grafana configuration file and the Secret that has your license.

  1. ---
  2. apiVersion: v1
  3. kind: PersistentVolumeClaim
  4. metadata:
  5. name: grafana
  6. spec:
  7. accessModes:
  8. - ReadWriteOnce
  9. resources:
  10. requests:
  11. storage: 1Gi
  12. storageClassName: local-path
  13. ---
  14. apiVersion: apps/v1
  15. kind: Deployment
  16. metadata:
  17. labels:
  18. app: grafana
  19. name: grafana
  20. spec:
  21. selector:
  22. matchLabels:
  23. app: grafana
  24. template:
  25. metadata:
  26. labels:
  27. app: grafana
  28. spec:
  29. containers:
  30. - image: grafana/grafana-enterprise:latest
  31. imagePullPolicy: IfNotPresent
  32. name: grafana
  33. ports:
  34. - containerPort: 3000
  35. name: http-grafana
  36. protocol: TCP
  37. readinessProbe:
  38. failureThreshold: 3
  39. httpGet:
  40. path: /robots.txt
  41. port: 3000
  42. scheme: HTTP
  43. initialDelaySeconds: 10
  44. periodSeconds: 30
  45. successThreshold: 1
  46. timeoutSeconds: 2
  47. resources:
  48. limits:
  49. memory: 4Gi
  50. requests:
  51. cpu: 100m
  52. memory: 2Gi
  53. volumeMounts:
  54. - mountPath: /var/lib/grafana
  55. name: grafana
  56. - mountPath: /etc/grafana
  57. name: ge-config
  58. - mountPath: /etc/grafana/license
  59. name: ge-license
  60. volumes:
  61. - name: grafana
  62. persistentVolumeClaim:
  63. claimName: grafana
  64. - name: ge-config
  65. configMap:
  66. name: ge-config
  67. - name: ge-license
  68. secret:
  69. secretName: ge-license
  70. ---
  71. apiVersion: v1
  72. kind: Service
  73. metadata:
  74. name: grafana
  75. spec:
  76. ports:
  77. - port: 3000
  78. protocol: TCP
  79. targetPort: http-grafana
  80. selector:
  81. app: grafana
  82. sessionAffinity: None
  83. type: LoadBalancer
  1. Send manifest to Kubernetes API Server 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 the Grafana login page.

  4. Use admin for both the username and password to login. If it worked, you should see Enterprise (Licensed) at the bottom of the page.