Skip to content
Dokumentatsiya
Kubernetes Monitoring

Kubernetes Monitoring

Ushbu amaliyotda biz Kubernetes clusterni monitoring qilishni ko'rib chiqamiz. Kubernetes monitoring qilishda Prometheus va Grafana ishlatamiz. Prometheus va Grafana haqida ma'lumot.

Ishni boshlash

Ushbu amaliyot uchun bizga kerak bo'ladi:

  • Ishlab turgan Kubernetes cluster
  • helm va NGINX Ingress Controller
  • Cert-Manager
  • Longhorn

Ushbu qo'llanmani yaxshi tushinish uchun quyidagi qo'llanmalarni ko'rib chiqish tavsiya qilinadi!

Rasmda Kubernetes Prometheus arxitekturasi (opens in a new tab)

Kubernetes Prometheus stackidagi komponentlar:

  • Prometheus Server
  • Alert Manager
  • Grafana

Prometheus o'rnatish

Keling Kubernetesga Prometheus, Grafana va boshqa monitoing toollarni ishlatish uchun monitoring nomli namespace ochib ishlaymiz.

1-> Monitoring uchun namespace yaratib olamiz.

kubectl create namespace monitoring

2-> Helm orqali Prometheus repositoriyani qo'shib monitoring namespacega o'rnatamiz.

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/prometheus --namespace monitoring

3-> Statusini tekshiramiz.

kubectl get pods -n monitoring
kubectl get svc -n monitoring

Okey hammasi yaxshi biz hozir Prometheusni o'rnatib oldik.

Metrics exporterlar o'rnatish

Kubernetes clasterimizni analiz qilib moinitoring qilishimiz uchun bizga metrics exporterlar kerak bo'ladi, ular Kubernetes cluster metrikalarini olib berib turadi.

1-> kube-state-metrics (opens in a new tab) o'rnatish

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-state-metrics prometheus-community/kube-state-metrics --namespace monitoring

2-> prometheus-node-exporter (opens in a new tab) o'rnatish

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace monitoring

Grafana o'rnatish

1-> Helm orqali Grafana repositoriyani qo'shib yangilab olamiz.

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

2-> helm orqali monitoring namespacega Grafana o'rnatamiz.

helm install grafana grafana/grafana --namespace monitoring

Grafan o'rnatib olganimzidan keyin uni domen ulab NGINX Ingress orqali expose qilamiz.

4-> grafana nomli papka ochib ichiga grafana-ingress.yaml configuratsiya fayl ochamiz.

mkdir grafana
cd grafana
nano grafana-ingress.yaml

5-> monitoing namespaceda grafana serviceni ko'rsak u 80 portda ishlab turibti.

Ya'ni grafana service monitoring namespaceda 80 portda ishlaydi.

Bizning grafana-ingress.yaml konfiguratsiyamiz quyidagicha.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-ingress
  namespace: monitoring
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  ingressClassName: "nginx"
  rules:
  - host: grafana.xilol.uz
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: grafana
            port:
              number: 80
  tls:
  - hosts:
    - grafana.xilol.uz
    secretName: grafana-tls

DNS hostimizdan Kubernetes clasterga domen ulab konfiguratsiyamizni apply qilamiz.

kubectl apply -f grafana-ingress.yaml

Grafana Dashboard sozlash

Grafana bu metrikalarni vizualizatsiya qilib beradigan tool hisoblanadi. Grafanaga Data Sourcelar ulanadi yani metrikalarni to'plab grafanaga beruvchilar bizning holatda bu Prometheus. Grafanaga Prometheusni ulab olganimizdan keyin Grafana Prometheus metrikalaridan foydalana oladi. Prometheusdagi metrikalarni vizualizatsiya qilish uchun esa Grafanaga dashboard qo'yiladi. Biz ushu amaliyot uchun github.com/dotdc/grafana-dashboards-kubernetes (opens in a new tab) dashboardlar to'plamini tanladik.

1-> Yuqorida Grafana o'rnatib domenga ulab expose qilgandik endi shu domen orqali grafana kiramiz bizda birinchi admin bo'lib login qilish oynasi ochilishi kerak.

  • Email or username-> admin
  • Password-> admin passwordni olish uchun quyidagi buyruqdan foydalansiz

admin user passwordni olish uchun

kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

2-> Grafanga login qilib kirib olganimizdan keyin Data Source sozlab olishimiz kerak yani Prometheusni ulab olishimiz kerak. Login qilib kirganimizdan keyin ochilgan Home pagedan DATA SOURCES bo'limga o'tamiz.

Data Sourceda Prometheusni tanlaymiz sizda quyidagi oyna ochiladi.

Connection bo'limdan Prometheus server URLga quyidagi URLNI beramiz.

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

va Save & test bosib ulab olamiz hammasi to'gri bo'lsa muvaffaqiyatli ulanishi kerak.

3-> Grafanaga Dashboard ulash uchun, Grafana boshqaruv paneliga qayting. To'rt kvadratdan iborat Dashboard ikonkasini tanlang va + Import-ni tanlang. 4-> Ushbu oynada Dashboard import qilamiz JSON model orqali yoki Grafana Dashboard ID orqali biz ID orqali import qilamiz. Biz github.com/dotdc/grafana-dashboards-kubernetes (opens in a new tab) Kubernetes Dashboardlar to'plamini tanlagandik unda Dashboardlar ID raqamlari belgilangan ushbu dashboardlarni ID orqali import qilamiz. Masalan biz k8s-views-global.json 15757 ni tanlaymiz va import qilamiz.

DashboardID
k8s-addons-prometheus.json19105
k8s-addons-trivy-operator.json16337
k8s-system-api-server.json15761
k8s-system-coredns.json15762
k8s-views-global.json15757
k8s-views-namespaces.json15758
k8s-views-nodes.json15759
k8s-views-pods.json15760

Undan keyingi oynada Data Sourcega Prometheusni belgilab Import qilamiz.

Bizda Grafana metrikalarni vizualizatsiya qilib ko'rsatishi kerak.

Okey yaxshi biz hammasini muvaffaqiyatli uddaladik endi qolgan dashboardlarni ham import qilib ulab chiqamiz.

Dashboardlar ro'yxati.

DashboardID
k8s-addons-prometheus.json19105
k8s-addons-trivy-operator.json16337
k8s-system-api-server.json15761
k8s-system-coredns.json15762
k8s-views-global.json15757
k8s-views-namespaces.json15758
k8s-views-nodes.json15759
k8s-views-pods.json15760

NGINX Ingress monitoring

Keling Prometheus Garafana orqali NGINX Ingressni ham monitoring qilamiz.

1-> NGINX Ingress controllerimizni yangilab exporterni yoqib prometheusga ulashimiz kerak.

helm upgrade ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx \
--set controller.metrics.enabled=true \
--set-string controller.podAnnotations."prometheus\.io/scrape"="true" \
--set-string controller.podAnnotations."prometheus\.io/port"="10254"

NGINX ingresni yangi konfiglarni qo'shib yangilab olganimzidan keyin valuelarni tekshirib olishimiz mumkin.

helm get values ingress-nginx --namespace ingress-nginx

Sizda quyidagi konfig chiqishi kerak.

USER-SUPPLIED VALUES:
controller:
  metrics:
    enabled: true
  podAnnotations:
    prometheus.io/port: "10254"
    prometheus.io/scrape: "true"

2-> NGINX Ingressni monitoring qilish uchun Dashboard import qilamiz. NGINX Ingress monitoring qilish uchun quyidagi JSON model dashboardan foydalanamiz.

Ushbu JSON kodni nusxalab dashboardni import qilishingiz mumkin: https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/grafana/dashboards/nginx.json (opens in a new tab)

NGINX ingress Controllerni monitoring qilish bo'yicha rasmiy qo'llanma. (opens in a new tab)

Qo'shimcha