Skip to content

SoftTn/prometheus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Prometheus + Grafana

๊ฐœ์š”

  • Kubernetes Monitoring ํˆด๋กœ์จ ๊ฑฐ์˜ ํ‘œ์ค€ํ™” ๋˜์–ด์žˆ๋Š” Prometheus์™€ ์‹œ๊ฐํ™” ํˆด์ธ Grafana๋ฅผ ์—ฐ๋™ํ•˜๋Š” ์‹ค์Šต์„ ์ง„ํ–‰ํ•ด๋ณด์•˜๋‹ค.

Prerequisites

  • Host OS : Ubuntu 18.04
  • Hypervisior : KVM
  • ๊ฐ€์ƒ๋จธ์‹ 
    • k-master
      • 192.168.100.10/24, RAM : 3GB, 2 vCPU
    • k-worker01
      • 192.168.100.20/24, RAM : 2GB, 2 vCPU
    • k-worker02
      • 192.168.100.21/24, RAM : 2GB, 2 vCPU
  • Kubernetes Cluster Version : 1.19.3

Architecture

  • Kubernetes ํด๋Ÿฌ์Šคํ„ฐ์˜ Metric ๊ฐ’ โ†’ Prometheus๊ฐ€ ์ˆ˜์ง‘ โ†’ Grafana๋กœ ์‹œ๊ฐํ™” (Web UI)

prometheus

์ „์ฒด์ ์ธ ์ˆœ์„œ

  1. Prometheus

    • namespace ์ƒ์„ฑ

      โ‡’ prometheus ๋งŒ์˜ ๋…ผ๋ฆฌ์ ์ธ ๊ณต๊ฐ„์„ ํ• ๋‹นํ•ด์ค€๋‹ค.

    • ClusterRole, ClusterRoleBinding, ServiceAccount ์ƒ์„ฑ

      โ‡’ Kubernetes Cluster ๋‚ด์˜ api์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ Prometheus๊ฐ€ ๋ถ€์—ฌ๋ฐ›๊ธฐ ์œ„ํ•œ ์ž‘์—…

      โ‡’ ClusterRole โ†” ClusterRoleBinding โ†” ServiceAccount

      โ‡’ ClusterRoleBinding์€ ๋ฐ”์ธ๋”ฉ๋งŒ ํ•ด์ฃผ๋Š” api ๋ฆฌ์†Œ์Šค์ด๋ฏ€๋กœ namespace๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์Œ

    • ConfigMap ์ƒ์„ฑ

      โ‡’ Configuration File ์ •์˜

      โ‡’ prometheus.rules : Metric์— ๋Œ€ํ•œ Alarm ์กฐ๊ฑด์„ ์ง€์ •, ํŠน์ • ์กฐ๊ฑด ๋‹ฌ์„ฑ ์‹œ AlertManager๋กœ ์•Œ๋žŒ์„ ๋ณด๋ƒ„

      โ‡’ prometheus.yml : Metric์˜ ์ข…๋ฅ˜, ์ˆ˜์ง‘ ์ฃผ๊ธฐ

    • Deployment ์ƒ์„ฑ

    • Service ์ƒ์„ฑ

  2. node exporter

    โ†’ Kubernetes ๊ธฐ๋ณธ System metric ์™ธ์˜ ๊ฒƒ๋“ค์„ ์ˆ˜์ง‘ํ•˜๊ธฐ ์œ„ํ•ด Agent๋ฅผ ๋”ฐ๋กœ ๋‘ 

    โ†’ ๊ฐ๊ฐ ํ•˜๋‚˜์”ฉ DaemonSet์œผ๋กœ ๋„์›Œ์คŒ

    • DaemonSet ์ƒ์„ฑ
    • Service ์ƒ์„ฑ
  3. kube-state-metrics

    โ†’ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด Object (Pod, ..)์— ๋Œ€ํ•œ ์ง€ํ‘œ ์ •๋ณด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์„œ๋น„์Šค

    โ†’ Pod ์ƒํƒœ ์ •๋ณด๋ฅผ Monitoringํ•˜๊ธฐ ์œ„ํ•ด kube-state-metrics๊ฐ€ ์žˆ์–ด์•ผ ํ•จ

    • ClusterRole, ClusterRoleBinding, ServiceAccount ์ƒ์„ฑ
    • Deployment, Service ์ƒ์„ฑ
  4. Grafana

    • Deployment, Service ์ƒ์„ฑ
  5. Prometheus - Grafana ์—ฐ๋™

    Grafana Dashboard์—์„œ Prometheus์˜ ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

    Endpoint๋Š” Prometheus Service์˜ ClusterIP๋ฅผ ๊ธฐ์ž…ํ•ด์ฃผ์–ด์•ผ ์„œ๋กœ ํŒŒ๋“œ ๊ฐ„์˜ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

  6. Dashboard ์ถ”๊ฐ€

์„ค์น˜

  • yaml ๋””๋ ‰ํ„ฐ๋ฆฌ ๋‚ด๋ถ€์— grafana, kube-state, prometheus ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ์žˆ๋‹ค.
  • ๊ฐ๊ฐ yaml ํŒŒ์ผ๋กœ ์ •์˜ํ•ด์ฃผ๊ณ  kubectl create -f << ~~.yaml >> ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.
## prometheus directory
kubectl create -f prometheus-cm.yaml 
kubectl create -f prometheus-crb.yaml 
kubectl create -f prometheus-cr.yaml 
kubectl create -f prometheus-deployment.yaml 
kubectl create -f prometheus-svc.yaml
kubectl create -f prometheus-node-exporter.yaml

## kube-state directory
kubectl create -f kube-state-crb.yaml
kubectl create -f kube-state-cr.yaml
kubectl create -f kube-state-sa.yaml
kubectl create -f kube-state-deployment.yaml
kubectl create -f kube-state-svc.yaml

## grafana directory
kubectl create -f grafana-deployment.yaml
kubectl create -f grafana-svc.yaml
  • tree๋กœ yaml ํŒŒ์ผ ํ™•์ธ
[root@k-master monitoring]# tree
.
โ”œโ”€โ”€ grafana
โ”‚ย ย  โ”œโ”€โ”€ grafana-deployment.yaml
โ”‚ย ย  โ””โ”€โ”€ grafana-svc.yaml
โ”œโ”€โ”€ kube-state
โ”‚ย ย  โ”œโ”€โ”€ kube-state-crb.yaml
โ”‚ย ย  โ”œโ”€โ”€ kube-state-cr.yaml
โ”‚ย ย  โ”œโ”€โ”€ kube-state-deployment.yaml
โ”‚ย ย  โ”œโ”€โ”€ kube-state-sa.yaml
โ”‚ย ย  โ””โ”€โ”€ kube-state-svc.yaml
โ””โ”€โ”€ prometheus
    โ”œโ”€โ”€ prometheus-cm.yaml
    โ”œโ”€โ”€ prometheus-crb.yaml
    โ”œโ”€โ”€ prometheus-cr.yaml
    โ”œโ”€โ”€ prometheus-deployment.yaml
    โ”œโ”€โ”€ prometheus-node-exporter.yaml
    โ””โ”€โ”€ prometheus-svc.yaml

3 directories, 13 files

Test

  • Prometheus server ์ ‘์†

    nodePort๋ฅผ ํ†ตํ•ด ์ ‘์†

Untitled

  • kube-state-metrics

    Prometheus ์„œ๋ฒ„ ์ƒ๋‹จ ๋ฉ”๋‰ด โ†’ Status โ†’ Target

    kube-state-metrics Healthy ํ•œ ๊ฒƒ์„ ํ™•์ธ

Untitled 1

  • Grafana

    nodePort๋ฅผ ํ†ตํ•ด ์ ‘์†

Untitled 2

  • Grafana - Prometheus ์—ฐ๋™ ์ž‘์—…

    • ์—ฐ๋™์€ Grafana์˜ Dashboard์—์„œ Prometheus์˜ Endpoint๋ฅผ ๊ธฐ์ž…ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.
    • Pod์™€ Pod ๊ฐ„์˜ ํ†ต์‹ ์ด๋ฏ€๋กœ ClusterIP๋ฅผ ๊ธฐ์ž…ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
    [root@k-master monitoring]# kubectl get svc -n monitoring 
    NAME                 TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
    grafana              NodePort   10.111.13.96     <none>        3000:30004/TCP   14m
    prometheus-service   NodePort   10.104.146.174   <none>        8080:30003/TCP   35m

Untitled 3

  • Dashboard๋ฅผ Importํ•ด์ฃผ์ž.

    Grafana ํ™ˆํŽ˜์ด์ง€ >> Dashboard๋กœ ์ด๋™ํ•˜์—ฌ ๋งˆ์Œ์— ๋“œ๋Š” Dashboard๋ฅผ ๊ฐ€์ ธ์˜ด.

Untitled 4

  • ์ตœ์ข… Test

Untitled 5

  • Reference

https://gruuuuu.github.io/cloud/monitoring-02/#

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published