> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/grafana/grafana/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Installation

> Deploy Grafana on Kubernetes using manifests or Helm charts

# Kubernetes Installation

This guide covers deploying Grafana on Kubernetes using Kubernetes manifests or Helm charts.

## Before You Begin

Ensure you have:

* A Kubernetes cluster (local or cloud-based)
  * Local: minikube, kind, or Docker Desktop
  * Cloud: GKE, EKS, or AKS
* `kubectl` CLI configured to access your cluster
* For Helm installation: Helm 3.x installed

## System Requirements

Minimum hardware requirements per pod:

* **CPU**: 250m (0.25 cores)
* **Memory**: 750 MiB
* **Disk**: 1 GB persistent storage

<Note>
  Ensure port 3000 is accessible in your network environment.
</Note>

## Installation with Kubernetes Manifests

Deploy Grafana using native Kubernetes manifests for full control over the deployment.

<Steps>
  ### Create a namespace

  ```bash theme={null}
  kubectl create namespace my-grafana
  ```

  ### Create the manifest file

  Create a file named `grafana.yaml` with the following contents:

  ```yaml theme={null}
  ---
  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
  ```

  ### Deploy the manifest

  ```bash theme={null}
  kubectl apply -f grafana.yaml --namespace=my-grafana
  ```

  ### Verify the deployment

  Check the PersistentVolumeClaim:

  ```bash theme={null}
  kubectl get pvc --namespace=my-grafana -o wide
  ```

  Check the Deployment:

  ```bash theme={null}
  kubectl get deployments --namespace=my-grafana -o wide
  ```

  Check the Service:

  ```bash theme={null}
  kubectl get svc --namespace=my-grafana -o wide
  ```

  ### Access Grafana

  Get all resources:

  ```bash theme={null}
  kubectl get all --namespace=my-grafana
  ```

  For cloud providers with LoadBalancer support, find the EXTERNAL-IP and access Grafana at `http://<EXTERNAL-IP>:3000`.

  For local clusters or if no external IP is available, use port forwarding:

  ```bash theme={null}
  kubectl port-forward service/grafana 3000:3000 --namespace=my-grafana
  ```

  Then access Grafana at `http://localhost:3000`.

  ### Sign in

  Default credentials:

  * Username: `admin`
  * Password: `admin`
</Steps>

## Installation with Helm

Helm simplifies Kubernetes deployments using packaged charts.

<Steps>
  ### Add the Helm repository

  ```bash theme={null}
  helm repo add grafana-community https://grafana-community.github.io/helm-charts
  ```

  ### Update the repository

  ```bash theme={null}
  helm repo update
  ```

  ### Create a namespace

  ```bash theme={null}
  kubectl create namespace monitoring
  ```

  ### Install Grafana

  ```bash theme={null}
  helm install my-grafana grafana-community/grafana --namespace monitoring
  ```

  ### Get admin password

  The Helm chart generates a random admin password stored in a Kubernetes secret:

  ```bash theme={null}
  kubectl get secret --namespace monitoring my-grafana \
    -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
  ```

  ### Access Grafana

  Use port forwarding:

  ```bash theme={null}
  export POD_NAME=$(kubectl get pods --namespace monitoring \
    -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=my-grafana" \
    -o jsonpath="{.items[0].metadata.name}")

  kubectl --namespace monitoring port-forward $POD_NAME 3000
  ```

  Access Grafana at `http://localhost:3000`.
</Steps>

## Helm Configuration

### Enable Persistent Storage

Create or download the `values.yaml` file from the [Grafana Helm Charts repository](https://github.com/grafana-community/helm-charts/blob/main/charts/grafana/values.yaml).

Edit `values.yaml` to enable persistence:

```yaml theme={null}
persistence:
  type: pvc
  enabled: true
  storageClassName: default
```

Apply the configuration:

```bash theme={null}
helm upgrade my-grafana grafana-community/grafana -f values.yaml -n monitoring
```

### Install Plugins

Add plugins to `values.yaml`:

```yaml theme={null}
plugins:
  - grafana-clock-panel
  - grafana-simple-json-datasource
```

Apply the configuration:

```bash theme={null}
helm upgrade my-grafana grafana-community/grafana -f values.yaml -n monitoring
```

### Custom Admin Password

Set a custom admin password in `values.yaml`:

```yaml theme={null}
adminUser: admin
adminPassword: your-secure-password
```

Apply the configuration:

```bash theme={null}
helm upgrade my-grafana grafana-community/grafana -f values.yaml -n monitoring
```

## Deploy Grafana Enterprise

To deploy Grafana Enterprise on Kubernetes:

<Steps>
  ### Create a license secret

  ```bash theme={null}
  kubectl create secret generic ge-license \
    --from-file=/path/to/your/license.jwt \
    --namespace=my-grafana
  ```

  ### Create Grafana configuration

  Create `grafana.ini`:

  ```ini theme={null}
  [enterprise]
  license_path = /etc/grafana/license/license.jwt

  [server]
  root_url = /your/license/root/url
  ```

  ### Create ConfigMap

  ```bash theme={null}
  kubectl create configmap ge-config \
    --from-file=/path/to/your/grafana.ini \
    --namespace=my-grafana
  ```

  ### Update deployment manifest

  Modify the Deployment section to use the Enterprise image and mount the license:

  ```yaml theme={null}
  containers:
    - image: grafana/grafana-enterprise:latest
      name: grafana
      volumeMounts:
        - mountPath: /var/lib/grafana
          name: grafana-pv
        - mountPath: /etc/grafana
          name: ge-config
        - mountPath: /etc/grafana/license
          name: ge-license
  volumes:
    - name: grafana-pv
      persistentVolumeClaim:
        claimName: grafana-pvc
    - name: ge-config
      configMap:
        name: ge-config
    - name: ge-license
      secret:
        secretName: ge-license
  ```

  ### Deploy

  ```bash theme={null}
  kubectl apply -f grafana.yaml --namespace=my-grafana
  ```
</Steps>

## Update Deployment

Perform rolling updates to change the Grafana version:

```bash theme={null}
kubectl edit deployment grafana --namespace=my-grafana
```

Change the image version:

```yaml theme={null}
image: grafana/grafana:12.1.0
```

Verify the rollout:

```bash theme={null}
kubectl rollout status deployment grafana --namespace=my-grafana
```

## Rollback Deployment

View rollout history:

```bash theme={null}
kubectl rollout history deployment grafana --namespace=my-grafana
```

Rollback to a previous revision:

```bash theme={null}
kubectl rollout undo deployment grafana --to-revision=1 --namespace=my-grafana
```

## Troubleshooting

### View logs

```bash theme={null}
kubectl logs --namespace=my-grafana deploy/grafana
```

For multi-container pods:

```bash theme={null}
kubectl logs --namespace=my-grafana deploy/grafana -c grafana
```

### Enable debug logging

Create a ConfigMap with custom configuration:

```bash theme={null}
echo '[log]
level = debug' > grafana.ini

kubectl create configmap grafana-config \
  --from-file=grafana.ini \
  --namespace=my-grafana
```

## Cleanup

Remove the Grafana deployment:

```bash theme={null}
kubectl delete -f grafana.yaml --namespace=my-grafana
```

For Helm installations:

```bash theme={null}
helm uninstall my-grafana -n monitoring
```

Delete the namespace:

```bash theme={null}
kubectl delete namespace my-grafana
```

## Next Steps

* Configure data sources using provisioning
* Set up persistent storage for production
* Configure high availability with multiple replicas
* Integrate with ingress controllers for external access
