티스토리 뷰
Kubernetes monitoring 을 하기 위한 솔루션으로 prometheus 를 설치하려고 한다.
기존에 prometheus를 서버 형태로 설치해본 경험은 있었지만, Kubernetes 환경에서는 서버 형태로 설치하면 metric을 scrape할 대상이 추가될 때마다 수동으로 서버를 재시작 해주기 어렵다.
따라서, Kubernetes 환경에서는 Operator형태의 prometheus를 설치해서 동적으로 metric을 scrape할 대상을 추가할 수 있도록 구성해볼 예정이다.
설치는 helm을 사용해서 prometheus operator chart를 이용했다.
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
위 사이트에서 helm 명령어 대로 실행을 해본다. (혹시 helm 이 설치되어 있지 않다면 설치부터 진행해준다… Mac이라서 brew install helm 으로 설치가 가능하다.. 아닌경우에는 공식 사이트를 참조하면 된다 https://helm.sh/docs/intro/install/)
Installing Helm
Learn how to install and get running with Helm.
helm.sh
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install [RELEASE_NAME] prometheus-community/kube-prometheus-stack
아래와 같이 helm repository를 먼저 추가해준다.
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositories
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" already exists with the same configuration, skipping
helm install 로 chart를 설치하기 전에 namespace를 먼저 생성하고 설치를 했다.
$ kubectl create ns monitoring
namespace/monitoring created
$ helm install wb-prometheus prometheus-community/kube-prometheus-stack -nmonitoring
NAME: wb-prometheus
LAST DEPLOYED: Fri Aug 18 08:55:45 2023
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
kubectl --namespace monitoring get pods -l "release=wb-prometheus"
Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.
위와 같은 결과가 나오면서 설치가 진행되며, 전부 정상 설치되는 것은 K8s Resource들을 확인해서 볼 수 있다.
설치된 구성요소들이 무엇이 있는지 살펴보자.
$ kubectl get all -nmonitoring
NAME READY STATUS RESTARTS AGE
pod/alertmanager-wb-prometheus-kube-prometh-alertmanager-0 2/2 Running 0 79s
pod/prometheus-wb-prometheus-kube-prometh-prometheus-0 2/2 Running 0 79s
pod/wb-prometheus-grafana-66f6c458c4-tbm9f 3/3 Running 0 81s
pod/wb-prometheus-kube-prometh-operator-69cb7478b6-n88xh 1/1 Running 0 81s
pod/wb-prometheus-kube-state-metrics-65d9578fdc-xqzrv 1/1 Running 0 81s
pod/wb-prometheus-prometheus-node-exporter-66bc7 1/1 Running 0 81s
pod/wb-prometheus-prometheus-node-exporter-rdwpx 1/1 Running 0 81s
pod/wb-prometheus-prometheus-node-exporter-t694g 1/1 Running 0 81s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 79s
service/prometheus-operated ClusterIP None <none> 9090/TCP 79s
service/wb-prometheus-grafana ClusterIP 10.108.223.14 <none> 80/TCP 81s
service/wb-prometheus-kube-prometh-alertmanager ClusterIP 10.105.3.120 <none> 9093/TCP,8080/TCP 81s
service/wb-prometheus-kube-prometh-operator ClusterIP 10.107.199.199 <none> 443/TCP 81s
service/wb-prometheus-kube-prometh-prometheus ClusterIP 10.101.30.107 <none> 9090/TCP,8080/TCP 81s
service/wb-prometheus-kube-state-metrics ClusterIP 10.98.224.89 <none> 8080/TCP 81s
service/wb-prometheus-prometheus-node-exporter ClusterIP 10.97.200.77 <none> 9100/TCP 81s
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/wb-prometheus-prometheus-node-exporter 3 3 3 3 3 kubernetes.io/os=linux 81s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/wb-prometheus-grafana 1/1 1 1 81s
deployment.apps/wb-prometheus-kube-prometh-operator 1/1 1 1 81s
deployment.apps/wb-prometheus-kube-state-metrics 1/1 1 1 81s
NAME DESIRED CURRENT READY AGE
replicaset.apps/wb-prometheus-grafana-66f6c458c4 1 1 1 81s
replicaset.apps/wb-prometheus-kube-prometh-operator-69cb7478b6 1 1 1 81s
replicaset.apps/wb-prometheus-kube-state-metrics-65d9578fdc 1 1 1 81s
NAME READY AGE
statefulset.apps/alertmanager-wb-prometheus-kube-prometh-alertmanager 1/1 79s
statefulset.apps/prometheus-wb-prometheus-kube-prometh-prometheus 1/1 79s
Pod 를 살펴보면 prometheus, alertmanager, grafana, prometheus operator, kube-state-metrics, node-exporter 등이 설치되어 있는 것을 볼 수 있다.
설치한 chart는 kube-prometheus 인데 관련 구성은 다음과 같이 되어 있다.
kube-prometheus Package - https://github.com/prometheus-operator/kube-prometheus
GitHub - prometheus-operator/kube-prometheus: Use Prometheus to monitor Kubernetes and applications running on Kubernetes
Use Prometheus to monitor Kubernetes and applications running on Kubernetes - GitHub - prometheus-operator/kube-prometheus: Use Prometheus to monitor Kubernetes and applications running on Kubernetes
github.com
Prometheus Operator는 Prometheus 관련 요소를 Kubernetes에 배포 및 관리 하는 기능을 제공하는 역할을 한다.
Prometheus는 Prometheus 서버를 의미한다.
Alertmanager는 Prometheus에서 감지된 Alarm을 외부로 notification 보내기 위한 용도이다.
Node exporter는 하드웨어, OS 매트릭을 수집하며, Go로 작성된 Plugin 형식 metric collector이다.
Prometheus Adapter for Kubernetes Metrics API 는 K8s의 HPA에 사용될 Custom Metric 지표를 생성해서 제공하기 위한 도구이다. 예를 들어 Pod에서 HTTP 요청에 대한 횟수를 Prometheus에 수집하고 이를 Prometheus Adapter를 통해서 Custom Metrics로 변환해서 HPA의 지표로 사용하는 방식이다.
kube-state-metrics는 Kubernetes API 서버를 수신하고 객체(K8s 객체들) 상태에 대한 지표를 생성하는 서비스다.
Grafana는 Prometheus와 같이 데이터 소스를 시각화 하는 서비스이다.
구성 패키지들에 대한 자세한 사항은 아래 github 내용을 통해서 확인이 가능하다.
Components included in this package:
- The Prometheus Operator
- Highly available Prometheus
- Highly available Alertmanager
- Prometheus node-exporter
- Prometheus Adapter for Kubernetes Metrics APIs
- kube-state-metrics
- Grafana
Minikube에 Prometheus Operator를 설치했는데, Prometheus나 Alertmanager, Grafana등을 접속해보기 위해서 NodePort로 변경해보려고 한다.
아래처럼 각 컴포넌트에 대한 service.type을 NodePort로 지정하는 yaml파일을 하나 작성한다.
prometheus:
service:
type: NodePort
grafana:
service:
type: NodePort
alertmanager:
service:
type: NodePort
그리고 위에서 수행했던 helm install 시에 -f 옵션을 이용해서 value file을 추가한다. 이런 경우 value file에 정의된 값을 우선적으로 적용하게 된다.
helm install wb-prometheus prometheus-community/kube-prometheus-stack -f prometheus-value.yaml -nmonitoring
이미 helm chart에 NodePort인 경우의 Port번호가 할당되어 있으며, 없는 경우 Kubernetes 에서 할당해준다.
$ kubectl get svc -nmonitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 10d
prometheus-operated ClusterIP None <none> 9090/TCP 10d
wb-prometheus-grafana NodePort 10.99.237.208 <none> 80:31575/TCP 10d
wb-prometheus-kube-prometh-alertmanager NodePort 10.100.208.186 <none> 9093:30903/TCP,8080:30321/TCP 10d
wb-prometheus-kube-prometh-operator ClusterIP 10.97.94.108 <none> 443/TCP 10d
wb-prometheus-kube-prometh-prometheus NodePort 10.105.53.89 <none> 9090:30090/TCP,8080:30648/TCP 10d
wb-prometheus-kube-state-metrics ClusterIP 10.107.215.168 <none> 8080/TCP 10d
wb-prometheus-prometheus-node-exporter ClusterIP 10.98.254.223 <none> 9100/TCP 10d
이후 접속을 위해서 minikube service 를 이용해서 로컬호스트에서 접속 가능한 상태로 만들어준다.
$ minikube service -nmonitoring --all
...
|------------|-----------------------------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|------------|-----------------------------------------|-------------|------------------------|
| monitoring | alertmanager-operated | | http://127.0.0.1:56946 |
| | | | http://127.0.0.1:56947 |
| | | | http://127.0.0.1:56948 |
| monitoring | prometheus-operated | | http://127.0.0.1:56950 |
| monitoring | wb-prometheus-grafana | | http://127.0.0.1:56952 |
| monitoring | wb-prometheus-kube-prometh-alertmanager | | http://127.0.0.1:56954 |
| | | | http://127.0.0.1:56955 |
| monitoring | wb-prometheus-kube-prometh-operator | | http://127.0.0.1:56957 |
| monitoring | wb-prometheus-kube-prometh-prometheus | | http://127.0.0.1:56959 |
| | | | http://127.0.0.1:56960 |
| monitoring | wb-prometheus-kube-state-metrics | | http://127.0.0.1:56962 |
| monitoring | wb-prometheus-prometheus-node-exporter | | http://127.0.0.1:56964 |
|------------|-----------------------------------------|-------------|------------------------|
...
prometheus를 설치한 namespace에 대한 minikube service를 수행하면 관련 service들을 찾고 NodePort인 경우 위에 처럼 접속 가능한 URL을 생성해준다.
출력된 URL주소를 통해서 해당 서비스에 브라우저로 접속이 가능하다.

다음에는 ServiceMonitor를 이용한 metric scrape을 수행해볼 예정이다.
'Kubernetes' 카테고리의 다른 글
| [Kubernetes] minikube 메모리 CPU 설정 (0) | 2024.02.18 |
|---|---|
| [Kubernetes] Mac OS Minikube 노드 추가하기 (0) | 2023.08.17 |
| [Kubernetes] Mac OS에 minikube로 Cluster 설치하기 (0) | 2023.08.17 |
- Total
- Today
- Yesterday
- Java 란
- 웹 애플리케이션
- docker-compose
- Kafka
- 데스크톱 애플리케이션
- Servlet Container
- 서버 클라이언트
- MySQL 외부 IP
- Prometheus Operator
- cpus
- producer
- 특정 ip
- OneToOne
- Spring Cloud Stream
- kubernetes
- 애노테이션 프로세서
- minikube node add
- Servlet
- consumer
- WEB-INF
- ExpectedException
- 애플리케이션 변화 과정
- minikube
- DD파일
- springboot3.x
- ServiceMonitor
- StreamBridge
- Java 장단점
- Java 특징
- node add
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
