Prometheus Operator란? (현재는 kube-prometheus-stack으로 이름을 변경함)
쿠버네티스 CRD(Custom resource definition)를 사용해 배포와 설정관리를 쉽게 만든 버전이다.
prometheus, alertmanager, monitoring기능이 포함되어 있다.
CRD를 통해 관리되는 리소스
Prometheus : 파드
Alertmanager : 파드
ThanosRuler : 파드
ServiceMonitor : 어떤 방식으로 클러스터를 모니터링할지 입력
PodMonitor : 어떤 방식으로 파드를 모니터링할지 입력
Prebe : 어떤 방식으로 ingress타겟을 모니터링할지 입력
PrometheusRule : 프로메테우스 룰 등록
AlertmanagerConfig : 알림매니저 설정
설치
- helm setup
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update
- install kube-prometheus
$ git clone https://github.com/prometheus-community/helm-charts.git
$ cd /charts/kube-prometheus-stack
$ vi values.yaml
$ helm install -n prometheus prom prometheus-community/kube-prometheus-stack --values values.yaml
- rule 추가
#프로메테우스는 rulesSelector의 라벨을 참조해서 rule을 찾아 등록함
#이벤트를 트리거하는 주체는 프로메테우스며 rule이 부합되면 트리거가 발생해 해당 이벤트를 alert.alertmanager에 설정된 alertmanager로 전송한다.
=> 즉 alertmanager는 프로메테우스가 전달한 이벤트를 쏴주는 미들웨어라 보면 된다.
$ kubectl edit -n prometheus Prometheus prom-kube-prometheus-stack-prometheus
#프로메테우스 룰 추가 (룰 추가후 파드 재시작없이 업데이트 됨)
#룰추가
$ kubectl get PrometheusRule -A
$ kubectl edit PrometheusRule prom-kube-prometheus-stack-alertmanager.rules
#테스트를 위한 룰 등록
(spec.groups.rules. 하위)
- alert: InstanceDownFromTest
expr: up == 0
for: 1m
- PVC 관련 룰 등록
kubectl edit PrometheusRule prom-kube-prometheus-stack-kubernetes-storage
kubelet_volume_stats_available_bytes{job="kubelet", namespace=~".*", metrics_path="/metrics"}
/
kubelet_volume_stats_capacity_bytes{job="kubelet", namespace=~".*", metrics_path="/metrics"}
) > 0.99
=> 이부분을 수정해서 알림 정책을 적용
- smtp정보 등록
알림매니저는 아래 시크릿을 통해 설정값을 관리한다.
alertmanager-prom-kube-prometheus-stack-alertmanager
#data.alertmanager.yaml라인에 설정값을 base64로 인코딩한 값을 넣어준다.
$vi config.yaml
global:
resolve_timeout: 5m
route:
group_by: ['job']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: 'kyc'
receivers:
- name: 'kyc'
email_configs:
- to: '<수신인-메일주소>'
from: '<smtp-mail>'
smarthost: <smtp-address-with-port>
auth_username: "<smtp-mail>"
auth_identity: "<smtp-mail>"
auth_password: "<pwd>"
#config파일 인코딩
$ cat config.yaml | base64 | tr -d '\n' > config-encode.yaml
#시크릿에 새로운값을 넣고 알림매니저 파드 삭제하면 재생성되면서 새로운 시크릿값을 업데이트 한다.
#알림매니저파드 접속
$ kubectl exec -it -n prometheus alertmanager-prom-kube-prometheus-stack-alertmanager-0 -c alertmanager sh
#config내용 확인
$ cat /etc/alertmanager/config/alertmanager.yaml
#alert 트리거 작동 플로우
alert는 route에 의해 분류되고 receiver에 의해 전송될 곳이 결정
helm 설치
helm install -n prometheus prom prometheus-community/kube-prometheus-stack --values values.yaml
helm upgrade -n prometheus prom prometheus-community/kube-prometheus-stack --values values.yaml
프로메테우스 삭제
helm uninstall -n prometheus prom
kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
kubectl delete crd alertmanagers.monitoring.coreos.com
kubectl delete crd podmonitors.monitoring.coreos.com
kubectl delete crd probes.monitoring.coreos.com
kubectl delete crd prometheuses.monitoring.coreos.com
kubectl delete crd prometheusrules.monitoring.coreos.com
kubectl delete crd servicemonitors.monitoring.coreos.com
kubectl delete crd thanosrulers.monitoring.coreos.com
#구글메일 사용시 "secure app access"를 꺼줘야함
https://myaccount.google.com/lesssecureapps
'Kubernetes' 카테고리의 다른 글
머신러닝 워크플로우를 위한 kubeflow 설치 및 CR,CRD 분석 (0) | 2022.06.25 |
---|---|
Kafka Operator 설치 및 테스트 (0) | 2022.06.11 |
컨테이너(Container) & 가상머신(VM) 비교 (0) | 2020.08.31 |
쿠버네티스 CKA 자격증 시험 후기 (0) | 2020.08.29 |
쿠버네티스(Kubernetes) 소개 (0) | 2020.07.11 |