[Kubernetes (K8S)] Helm install kube-prometheus stack with Grafana to collect logs within Kubernetes (K8S)

kube-prometheus stack

Installs the kube-prometheus stack, a collection of Kubernetes manifests, Grafana dashboards, and Prometheus rules combined with documentation and scripts to provide easy to operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus Operator.

This article is about how to use Helm to deploy kube-prometheus stack (Prometheus, Grafana) on Kubernetes (K8S).

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

    For more information about installing and using Kubernetes (K8s), see the Kubernetes (K8s) Docs.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

    For more information about installing and using Helm, see the Helm Docs.

Installation

Custom Values.yaml

Remember to replace the content within < > with your info.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# values.yaml

# helm-charts/values.yaml at main · prometheus-community/helm-charts
# https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml

## Configuration for alertmanager
## ref: https://prometheus.io/docs/alerting/alertmanager/
##
alertmanager:

ingress:
enabled: true

annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: 'true'
cert-manager.io/acme-challenge-type: dns01
cert-manager.io/cluster-issuer: cert-manager-webhook-dnspod-cluster-issuer

## Kubernetes Dashboard Ingress hostnames
## Must be provided if Ingress is enabled
##
hosts:
- <Your Alertmanager Host>

## Kubernetes Dashboard Ingress TLS configuration
## Secrets must be manually created in the namespace
##
tls:
- secretName: cert-manager-webhook-dnspod-letsencrypt
hosts:
- <Your Alertmanager Host>

## Using default values from https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml
##
grafana:

adminPassword: <Your Grafana Password>

ingress:
## If true, Kubernetes Dashboard Ingress will be created.
##
enabled: true

annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: 'true'
cert-manager.io/acme-challenge-type: dns01
cert-manager.io/cluster-issuer: cert-manager-webhook-dnspod-cluster-issuer

## Kubernetes Dashboard Ingress hostnames
## Must be provided if Ingress is enabled
##
hosts:
- <Your Grafana Host>

## Kubernetes Dashboard Ingress TLS configuration
## Secrets must be manually created in the namespace
##
tls:
- secretName: cert-manager-webhook-dnspod-letsencrypt
hosts:
- <Your Grafana Host>

## Deploy a Prometheus instance
##
prometheus:

ingress:
## If true, Kubernetes Dashboard Ingress will be created.
##
enabled: true

annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: 'true'
cert-manager.io/acme-challenge-type: dns01
cert-manager.io/cluster-issuer: cert-manager-webhook-dnspod-cluster-issuer

## Kubernetes Dashboard Ingress hostnames
## Must be provided if Ingress is enabled
##
hosts:
- <Your Prometheus Host>

## Kubernetes Dashboard Ingress TLS configuration
## Secrets must be manually created in the namespace
##
tls:
- secretName: cert-manager-webhook-dnspod-letsencrypt
hosts:
- <Your Prometheus Host>

Install by Helm

Helm install kube-prometheus-stack into kube-prometheus-stack namespace.

1
2
3
4
5
6
7
8
9
10
11
12
13
# crate namespace:
$ kubectl create namespace kube-prometheus-stack

# Add the Helm repository:
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

$ helm repo add stable https://charts.helm.sh/stable

# Update your local Helm chart repository cache:
$ helm repo update

# To install Helm chart:
$ helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack -n kube-prometheus-stack -f values.yaml

See Helm release about kube-prometheus-stack.

1
2
3
$ helm list --namespace kube-prometheus-stack
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
kube-prometheus-stack kube-prometheus-stack 1 2020-10-31 17:22:26.958742 +0800 +0800 deployed kube-prometheus-stack-10.3.1 0.42.1

See pods about kube-prometheus-stack.

1
2
3
4
5
6
7
8
$ kubectl get pods -n kube-prometheus-stack
NAME READY STATUS RESTARTS AGE
alertmanager-kube-prometheus-stack-alertmanager-0 2/2 Running 12 15d
kube-prometheus-stack-grafana-7477779768-jgcm5 0/2 Completed 8 15d
kube-prometheus-stack-kube-state-metrics-5cf575d8f8-kzdvk 0/1 Running 5 15d
kube-prometheus-stack-operator-6b7fcccf89-ffb4q 2/2 Running 14 13d
kube-prometheus-stack-prometheus-node-exporter-5jcjl 1/1 Running 6 15d
prometheus-kube-prometheus-stack-prometheus-0 3/3 Running 10 4d

Then, you can visit Grafana, Prometheus or Alertmanager:

  • https://

  • https://

  • https://

References

[1] helm-charts/charts/kube-prometheus-stack at main · prometheus-community/helm-charts - https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

[2] Prometheus - Monitoring system & time series database - https://prometheus.io/

[3] Grafana: The open observability platform | Grafana Labs - https://grafana.com/

[4] Helm - https://helm.sh/

[5] Kubernetes - https://kubernetes.io/