- Kubernetes Monitoring ํด๋ก์จ ๊ฑฐ์ ํ์คํ ๋์ด์๋ Prometheus์ ์๊ฐํ ํด์ธ Grafana๋ฅผ ์ฐ๋ํ๋ ์ค์ต์ ์งํํด๋ณด์๋ค.
- 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
- k-master
- Kubernetes Cluster Version : 1.19.3
- Kubernetes ํด๋ฌ์คํฐ์ Metric ๊ฐ โ Prometheus๊ฐ ์์ง โ Grafana๋ก ์๊ฐํ (Web UI)
-
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 ์์ฑ
-
-
node exporter
โ Kubernetes ๊ธฐ๋ณธ System metric ์ธ์ ๊ฒ๋ค์ ์์งํ๊ธฐ ์ํด Agent๋ฅผ ๋ฐ๋ก ๋
โ ๊ฐ๊ฐ ํ๋์ฉ DaemonSet์ผ๋ก ๋์์ค
- DaemonSet ์์ฑ
- Service ์์ฑ
-
kube-state-metrics
โ ์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ ๋ด Object (Pod, ..)์ ๋ํ ์งํ ์ ๋ณด๋ฅผ ์์ฑํ๋ ์๋น์ค
โ Pod ์ํ ์ ๋ณด๋ฅผ Monitoringํ๊ธฐ ์ํด kube-state-metrics๊ฐ ์์ด์ผ ํจ
- ClusterRole, ClusterRoleBinding, ServiceAccount ์์ฑ
- Deployment, Service ์์ฑ
-
Grafana
- Deployment, Service ์์ฑ
-
Prometheus - Grafana ์ฐ๋
Grafana Dashboard์์ Prometheus์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ฃผ์ด์ผ ํ๋ค.
Endpoint๋ Prometheus Service์ ClusterIP๋ฅผ ๊ธฐ์ ํด์ฃผ์ด์ผ ์๋ก ํ๋ ๊ฐ์ ํต์ ์ด ๊ฐ๋ฅํ๋ค.
-
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-
Prometheus server ์ ์
nodePort๋ฅผ ํตํด ์ ์
-
kube-state-metrics
Prometheus ์๋ฒ ์๋จ ๋ฉ๋ด โ Status โ Target
kube-state-metrics Healthy ํ ๊ฒ์ ํ์ธ
-
Grafana
nodePort๋ฅผ ํตํด ์ ์
-
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
-
Dashboard๋ฅผ Importํด์ฃผ์.
Grafana ํํ์ด์ง >> Dashboard๋ก ์ด๋ํ์ฌ ๋ง์์ ๋๋ Dashboard๋ฅผ ๊ฐ์ ธ์ด.
- ์ต์ข Test
- Reference






