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.
- Prometheus nima? (opens in a new tab)
- Grafana nima? (opens in a new tab)
- Grafana Dashboardni import qilish (opens in a new tab)
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!
-
Ishlashga tayyor Kubernetes yaratish uchun: Kubernetes klaster yaratish va sozlash(kubeadm) (opens in a new tab)
-
Cert-Manager uchun: Kubernetesga Cert-Manager o'rnatish va sozlash (opens in a new tab)
-
Longhorn uchun: Longhorn o'rnatish va sozlash (opens in a new tab)
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.
Dashboard | ID |
---|---|
k8s-addons-prometheus.json | 19105 |
k8s-addons-trivy-operator.json | 16337 |
k8s-system-api-server.json | 15761 |
k8s-system-coredns.json | 15762 |
k8s-views-global.json | 15757 |
k8s-views-namespaces.json | 15758 |
k8s-views-nodes.json | 15759 |
k8s-views-pods.json | 15760 |
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.
Dashboard | ID |
---|---|
k8s-addons-prometheus.json | 19105 |
k8s-addons-trivy-operator.json | 16337 |
k8s-system-api-server.json | 15761 |
k8s-system-coredns.json | 15762 |
k8s-views-global.json | 15757 |
k8s-views-namespaces.json | 15758 |
k8s-views-nodes.json | 15759 |
k8s-views-pods.json | 15760 |
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
Qo'shimcha Resurslar
- Kubernetesga Kirish (opens in a new tab)
- Kubernetes Arxitekturasi (opens in a new tab)
- Kubernetes Obyektlari (opens in a new tab)
- Kubernetes cluster yaratish va sozlash(kubeadm) (opens in a new tab)
- Kubernetesga Argo CD o'rnatish va sozlash (opens in a new tab)
- Kuberntes CI/CD | Github Actions + Argo CD | GitOps (opens in a new tab)
Sana: 2024.02.07(2024-yil 7-fevral)
Oxirgi yangilanish: 2024.02.07(2024-yil 7-fevral)
Muallif: Otabek Ismoilov
Telegram (opens in a new tab) | Github (opens in a new tab) | LinkedIn (opens in a new tab) |
---|