Инсталляция с помощью Helm инструментов мониторинга


Запуск Prometheus (мониторинг) и Grafana (визуализация) в kuberntes cluster с помощью heml (только для теста)


Делаю:
09.02.2021


Upd:

Похоже все будет в ближайшее время кучей ставиться одной командой:

https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack#multiple-releases


$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

$ helm repo update

$ kubectl create namespace monitoring

// Без ключа serviceMonitorSelectorNilUsesHelmValues=false
// Не стартовали сервис мониторы и не добавлялись в target и configuration
$ helm install prometheus-stack prometheus-community/kube-prometheus-stack --namespace monitoring \
  --set kubelet.serviceMonitor.https=true \
  --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \
  --set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
  --set prometheus.prometheusSpec.ruleSelectorNilUsesHelmValues=false

$ export POD_NAME=prometheus-prometheus-stack-kube-prom-prometheus-0

$ kubectl --namespace monitoring port-forward $POD_NAME 9090

localhost:9090


Полезный конфиг взял здесь:
https://docs.fission.io/docs/observability/prometheus/


Как делалось ранее

Запускаю локальный kubernetes кластер


$ kubectl get nodes
NAME     STATUS   ROLES                  AGE     VERSION
master   Ready    control-plane,master   11m     v1.20.2
node1    Ready    <none>                 7m1s    v1.20.2
node2    Ready    <none>                 2m38s   v1.20.2


Устанавливаю Helm3 на localhost.


$ mkdir ~/kubernetes-configs && cd ~/kubernetes-configs


Вроде оф.дока:

https://github.com/prometheus-community/helm-charts


$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts


01. Prometheus

$ vi prometheus-values.yml
alertmanager:
  persistentVolume:
    enabled: false
server:
  persistentVolume:
    enabled: false


$ kubectl create namespace prometheus

$ helm install prometheus \
    prometheus-community/prometheus \
    -f prometheus-values.yml \
    --namespace prometheus

$ kubectl get pods -n prometheus


$ helm list -n prometheus
NAME      	NAMESPACE 	REVISION	UPDATED                                	STATUS  	CHART            	APP VERSION
prometheus	prometheus	1       	2021-02-04 15:12:10.794089007 +0300 MSK	deployed	prometheus-13.2.1	2.24.0


$ export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")

$ kubectl --namespace prometheus port-forward $POD_NAME 9090

http://localhost:9090/graph


02. Grafana


https://grafana.com/docs/loki/latest/installation/helm/

$ helm repo add grafana https://grafana.github.io/helm-charts


$ helm repo update


$ vi grafana-values.yml
adminPassword: password

$ kubectl create namespace loki

$ helm upgrade --install loki \
    grafana/loki \
    --namespace=loki


$ kubectl create namespace grafana

$ helm install loki-grafana \
    grafana/grafana \
    -f grafana-values.yml \
    --namespace grafana


$ kubectl get pods -n grafana
NAME                           READY   STATUS    RESTARTS   AGE
loki-grafana-bd544cfcb-5rgds   1/1     Running   0          56s


$ export POD_NAME=$(kubectl get pods --namespace grafana -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=loki-grafana" -o jsonpath="{.items[0].metadata.name}")

$ kubectl --namespace grafana port-forward $POD_NAME 3000


http://localhost:3000/


admin / password


Add data source - Prometheus

Name: Prometheus

URL: http://prometheus-server.prometheus.svc.cluster.local

Save and test


Пример запуска приложения с метриками:

Здесь