[k8s] kube-prometheus-stack
kube-prometheus-stack์ k8s ํด๋ฌ์คํฐ์์ Grafana+Prometheus ๊ธฐ๋ฐ์ ๋ฆฌ์์ค ๋ชจ๋ํฐ๋ง์ ์ฝ๊ฒ ๊ตฌ์ฑํ ์ ์๊ฒ ํด์ฃผ๋ ์์ปท ํจํค์ง๋ค.
์ด๋ค ๋ ธ๋์์ ์ผ๋ง๋ ๋ฆฌ์์ค๋ฅผ ์ฐ๋์ง, Pod๋ค์ด ๋ฆฌ์์ค๋ฅผ ์ผ๋ง๋ ๋จน๊ณ ์๋์ง ๋ฑ์ ์ฝ๊ฒ ํ์ ํ ์ ์๊ฒ ํด์ค๋ค.
helm์ ํตํด ๊ฐํธํ๊ฒ ์ค์นํ ์ ์๋ค.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack
์ค์นํ๊ณ ๋๋ฉด, ๋ค์ ๋ช
๋ น์ ์ฌ์ฉํด์ ์ ์์ ์ผ๋ก ์คํ์ด ๋๋์ง๋ฅผ ๋จผ์ ํ์ธํด๋ณด์.
kubectl --namespace default get pods -l "release=prometheus"
๋ค Running์ด๋ฉด ์ ์์ด๋ค.
์ด์ Grafana ๋์๋ณด๋์ ๋ํ ์๋ํฌ์ธํธ๋ฅผ ๋ซ์ด์ผ ํ๋ค. ์จํ๋ ๋ฏธ์ค ํ๊ฒฝ์ธ ๊ฒฝ์ฐ์๋ ์ ๋นํ ์ธ๋ถIP ์ด๋ฉด ๋๊ณ , ํด๋ผ์ฐ๋๋ผ๋ฉด ๋ก๋๋ฐธ๋ฐ์๋ฅผ ์ฐ๋ฉด ๋๋ค.
kubectl patch svc prometheus-grafana --type=json -p='[{"op": "replace", "path": "/spec/ports", "value": [{"name":"default", "port":28080, "targetPort": 3000, "protocol": "TCP"}]}]'
kubectl patch svc prometheus-grafana -p '{"spec": {"type":"ClusterIP", "externalIPs": ["192.168.0.8"]}}'๋์๋ณด๋ ์ ์
๋ฐฉ๊ธ ์ด์ด๋์ Grafana ๋์๋ณด๋ Serive์ IP๋ก ๋ค์ด๊ฐ๋ฉด ๋ก๊ทธ์ธ์ฐฝ๋ถํฐ ๋ฐ ๊ฒ์ด๋ค.

๊ธฐ๋ณธ ๊ด๋ฆฌ์ username์ admin์ธ๋ฐ, ํจ์ค์๋๋ ๋๋ค์ด๋ผ์ ์ํฌ๋ฆฟ์ ํตํด ์ฝ์ด์์ผ ํ๋ค.
kubectl --namespace default get secrets prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 -d ; echo
์ด๊ฑธ ํจ์ค์๋๋ก ๋ฃ๊ณ ๋ก๊ทธ์ธํ๋ฉด ๋๋ค.
๊ทธ๋ผ ์์ ๊ฐ์ ๋ค์ํ ๋์๋ณด๋๋ค์ด ๊น๋ ค์์ ๊ฒ์ด๋ค.
์ด๊ฒ ๋ค ๋ด๋ถ์ ์ผ๋ก ํด๋ฌ์คํฐ ์ ๋ณด๋ฅผ ๊ณ์ ์ฝ์ผ๋ฉด์ prometheus์ ๋ฉํธ๋ฆญ์ ์๊ณ , ๊ทธ๊ฑธ ์๊ฐํํด์ฃผ๋ ๊ฒ๋ค์ด๋ค.
๋ณด๊ณ ์ถ์ ๊ฒ๋ง ๊ณจ๋ผ์ ๋ณด๋ฉด ๋๋ค.
์ด๊ฑด ํด๋ฌ์คํฐ ์ ์ฒด์ ์ฌ์ฉ๋ ํต๊ณ๊ณ
CoreDNS ์์ค ํธ๋ํฝ ํต๊ณ

๋
ธ๋๋ค์ด ๋ฆฌ์์ค๋ฅผ ์ผ๋ง๋ ์ฐ๊ณ ์๋์ง
์ด๊ฑด ๊ฐ๋ณ Pod์ ๋ํ ํต๊ณ๋ค.
์ฑ๋ฅ์ด๋ ์ฌ์ฉ๋ ์กฐ์ฌ ์งํ๋ก ํ์ฉํ๋ฉด ๋๋ค.
์ฐธ์กฐ
https://leehosu.github.io/kube-prometheus-stack
https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack