본문 바로가기
클라우드/Prometheus

Kubernetes 에서 Prometheus Stack 설치하기(Grafana, Node Exporter)

by 정권이 내 2022. 12. 13.

 

img

 

 

Kubernetes 에서 Prometheus 설치하기(Helm)

 

클라우드 환경에서 시스템 모니터링을 할때 주로 사용하는 오픈소스 툴인 Prometheus 설치방법에 대해 설명 해보겠습니다.

Prometheus 공식 Github에서 helm chart를 제공하고 있으며 그중 kube-prometheus-stack 에서 시스템모니터링을 위한 Grafana, Prometheus-Operator, Prometheus, NodeExporter 등이 포함되어 있습니다.

 

설치 필요사항

  • Kubernetes 1.16 이상
  • Helm 3 이상

 

1. Helm 레포지토리 추가 및 다운

가장 먼저 Prometheus 공식 Github에 있는 레포지토리를 helm을 이용하여 추가해야 합니다.

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update

 

prometheus-community 안에는 여러가지 chart 들이 있습니다.

img

 

Prometheus 환경을 구성할수 있는 chart인 kube-prometheus-stack을 받아야 하므로 아래와 같이 진행합니다.

$ helm pull prometheus-community/kube-prometheus-stack

 

그러면 가장 최신버전의 kube-prometheus-stack-[Release Version].tgz 형식의 이름으로 파일이 다운로드 되는데 해당 파일의 압축을 해제합니다.

$ tar xvfz kube-prometheus-stack-42.3.0.tgz

img

 

 

2. values.yaml 설정

이상태에서 바로 실행해도 되지만 values.yaml 파일을 수정하여 커스텀하게 사용할수 있습니다. 세부 설정은 건너뛰고 Grafana의 초기 비밀번호만 변경 해보겠습니다.

최초 비밀번호는 "prom-operator" 로 설정되있는데 원하는 비밀번호로 변경해줍니다.

img

 

3. kube-prometheus-stack 설치

설치는 helm 명령어를 이용합니다. git 저장소가 아닌 로컬 경로에서 설치하므로 아래와 같이 설치 명령어를 입력합니다.

$ helm install prometheus . -n monitoring -f values.yaml

helm 설치시 기본값이 values.yaml을 바라보게 되있어서 -f values.yaml 는 생략해도 되는 부분인데 파일을 values.yaml 을 다른이름으로 사용한다면 -f 옵션으로 파일이름을 명시해야 합니다.

 

설치시 오류 해결 ( Internal error occurred: failed calling webhook )

가끔 설치하다가 아래와 같은 오류가 발생하는 경우가 있습니다.

Error: INSTALLATION FAILED: Internal error occurred: failed calling webhook "prometheusrulemutate.monitoring.coreos.com": failed to call webhook: Post "https://prometheus-operator.monitoring.svc:443/admission-prometheusrules/mutate?timeout=10s": service "prometheus-operator" not found

 

kube-prometheus-stack 을 설치하기전에 다른 prometheus를 설치했었다면 webhook config에서 꼬이는 경우가 종종 발생하는데 기존에 존재하는 config를 삭제하면 해결됩니다.

https://github.com/prometheus-community/helm-charts/issues/108#issuecomment-703266597

 

아래 명령어로 webhook config 설정을 검색합니다.

$ kubectl get validatingwebhookconfigurations
$ kubectl get MutatingWebhookConfiguration

img

img

 

목록에서 prometheus 이름이 들어간것을 찾았다면 delete 명령으로 삭제후 재설치 하면 정상적으로 실행됩니다.

$ kubectl delete validatingwebhookconfigurations/prometheus-admission
$ kubectl delete MutatingWebhookConfiguration/prometheus-admission

 

설치시 오류 해결 ( unknown field "hostNetwork" )

Error: INSTALLATION FAILED: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Prometheus.spec): unknown field "hostNetwork" in com.coreos.monitoring.v1.Prometheus.spec

 

이전에 설치된 Prometheus의 버전과 동일하지 않은 버전의 Prometheus가 설치될경우 발생하는 오류입니다. helm delete 명령어를 통해 기존 Prometheus를 제거 하더라도 쿠버네티스 클러스터에는 관련 리소스가 남아있는데 이전 버전 설치시 남아있는 리소스를 제거하고 진행해야 합니다.

https://github.com/prometheus-community/helm-charts/issues/2753#issuecomment-1345262355

 

아래 명령어로 prometheus의 crds를 검색하여 제거합니다.

$ kubectl get crds | grep prometheus

prometheuses.monitoring.coreos.com          2022-12-16T06:57:19Z
prometheusrules.monitoring.coreos.com       2022-12-16T06:57:19Z
$ kubectl delete crds prometheuses.monitoring.coreos.com
$ kubectl delete crds prometheusrules.monitoring.coreos.com

제거후 설치를 진행하면 정상적으로 실행됩니다.

 

 

4. 설치 확인 및 UI 접속

 

$ helm list -n monitoring

img

STATUS 가 deployed로 보인다면 정상적으로 helm install 설치가 된것입니다.

 

$ kubectl get pod -n monitoring
$ kubectl get svc -n monitoring

img

쿠버네티스 클러스터에도 정상적으로 파드와 서비스가 실행중인것이 확인됩니다.

 

웹 브라우저에서 NodePort를 이용해 Grafana와 Prometheus에 접근 해보겠습니다. Grafana, Prometheus 는 외부에서 UI를 접속할수 있도록 서비스를 NodePort 타입으로 설정해놓았습니다.

img

img

 

Prometheus의 node exporter에서 메트릭 데이터를 정상적으로 수집하는지 확인하기 위해 Grafana에 대시보드를 만들어서 확인해보겠습니다.

대시보드는 https://grafana.com/grafana/dashboards/1860-node-exporter-full/ 를 사용했습니다.

img

 

 

참고 사이트

https://grafana.com/grafana/dashboards/1860-node-exporter-full/

https://github.com/prometheus-community/helm-charts/issues/108#issuecomment-703266597

https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

 

반응형

댓글