Skip to content

Installation in Kubernetes

This section documents how to install Grafana and Prometheus into a Kubernetes cluster. For installation in OpenShift, use the Installation in OpenShift instructions. You can use Prometheus and Grafana to monitor the Kubernetes cluster, including IEM resources.

Preparations

Create a new namespace (replace {namespace} with the namespace name, for example grafana):

kubectl create namespace {namespace}

Use the following command to create a secret containing the Grafana admin password: replace {namespace} with the namespace name (for example grafana); {username} with the admin username (for example admin); and {password} with the admin password:

kubectl --namespace {namespace} create secret generic grafana-admin --from-literal=admin-user={username} --from-literal=admin-password={password}

This username and password can be used later to log into Grafana.

Install the Grafana Loki Stack

Run the following commands in a Bash console, (replace {namespace} with the namespace name, for example grafana):

NAMESPACE={namespace}
helm upgrade --install loki grafana/loki-stack --version='^2.8.0' --namespace=${NAMESPACE} --set grafana.enabled=true,grafana.persistence.enabled=true,grafana.persistence.size=1Gi,grafana.initChownData.enabled=false,grafana.admin.existingSecret=grafana-admin \
--set prometheus.enabled=true,prometheus.server.persistentVolume.enabled=true,prometheus.server.persistentVolume.size=50Gi,prometheus.server.retention=7d \
--set loki.persistence.enabled=true,loki.persistence.size=10Gi,loki.config.chunk_store_config.max_look_back_period=168h,loki.config.table_manager.retention_deletes_enabled=true,loki.config.table_manager.retention_period=168h \
--set promtail.enabled=true,promtail.containerSecurityContext.privileged=true,promtail.containerSecurityContext.allowPrivilegeEscalation=true \
--set prometheus.nodeExporter.enabled=false,prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false

This Helm chart will install and configure Grafana, Prometheus, Loki, and their dependencies.

You might need to adjust some parameters to match the scale and requirements of your environment:

  • grafana.persistence.size – specifies the volume size used by Grafana to store its configuration;
  • prometheus.server.persistentVolume.size – specifies the volume size used by Prometheus to store metrics;
  • prometheus.server.retention – specifies how long metrics are kept by Prometheus before they will be discarded;
  • loki.persistence.size – specifies the volume size used by Loki to store logs;
  • loki.config.chunk_store_config.max_look_back_period – specifies the maximum retention period for storing chunks (compressed log entries);
  • loki.config.table_manager.retention_period – specifies the maximum retention period for storing logs in indexed tables;

For more details see the Loki installation guide.

If your Kubernetes cluster requires a StorageClass to be specified, add the following arguments to the helm upgrade command (replace {class} with a storage class name, e.g. gp2):

--set grafana.persistence.storageClassName={class},loki.persistence.storageClassName={class},prometheus.server.persistentVolume.storageClass={class}

Expose the Grafana Web UI

Create an Ingress object to access Grafana from your web browser: replace {namespace} with the namespace name (for example grafana); {domain} with the domain name (for example grafana.iem.example.com):

kubectl --namespace={namespace} create ingress loki-grafana \
--rule="{domain}/*=loki-grafana:80,tls" \
--default-backend="loki-grafana:80"