kubernetes
Prometheus on kubernetes
mingming_96
2023. 9. 18. 00:45
prometheus를 설치하는 실습입니다. helm 으로 간단하게 설치 가능합니다.
사전 준비사항
1. nfs server
prometheus-server 가 pvc를 통해 pv를 사용할 수 있도록 nfs server를 구성한 후 pv를 생성해 줍니다.
2. helm install
helm을 통해 설치하기 때문에 helm 명령어가 설치되어 있어야 합니다.
3. metal lb
prometheus-server를 외부에서 접근 가능하도록 LoadBalancer type으로 노출 시키기 위해 metallb가 설치되어 있어야 합니다. | svc port forwarding 혹은 Nodeport 로 노출시켜도 됩니다.
helm repo add
프로메테우스 커뮤니티에서 제공하는 helm chart를 이용합니다. | artifacthub
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
create namespace
promethues가 사용할 namespace를 생성해 줍니다.
kubectl create namespace promehteus
먼저 prometheus helm chart의 기본 설정 정의 파일인 values.yaml 파일을 가져옵니다.
helm show prometheus/prometheus > values.yaml
pv 생성
prometheus-server-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus-pv
spec:
capacity:
storage: 8Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
nfs:
server: 192.168.45.240
path: /nfs_shared/prometheus
alertmanager-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: alertmanager-pv
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
nfs:
server: 192.168.56.103
path: /nfs_shared/alertmanager
kubectl apply -f prometheus-server-pv.yaml
kubectl apply -f alertmanager-pv.yaml
Valuefile Definition
vim values.yaml
434 ## Prometheus server data Persistent Volume mount root path
435 ##
436 mountPath: /data
437
438 ## Prometheus server data Persistent Volume size
439 ##
440 size: 8Gi
------------------------------- 중략 -------------------------------
473 ## Persistent Volume Name
474 ## Useful if Persistent Volumes have been provisioned in advance and you want to use a specific one
475 ##
476 volumeName: "prometheus-pv" ## 주석 해재 후 생성한 pv 이름으로 수정해 줍니다.
------------------------------- 중략 -------------------------------
1181 alertmanager:
1182 ## If false, alertmanager will not be installed
1183 ##
1184 enabled: true ## 필요에따라 false 가능
1185
1186 persistence:
1187 size: 2Gi
1188
1189 podSecurityContext:
1190 runAsUser: 65534
1191 runAsNonRoot: true
1192 runAsGroup: 65534
1193 fsGroup: 65534
prometheus install
수정한 values.yaml 파일을 이용해 prometheus 를 설치합니다.
helm install prometheus prometheus-community/prometheus -f values.yaml --namespace monitoring
kubectl get all -n monitoring
prometheus Service Expose
kubectl patch svc prometheus-server -p '{"spec":{"type":"LoadBalancer"}}'
kubectl patch svc prometheus-server -p '{"spec":{"type":"NodePort"}}'
할당받은 metallb 주소로 접근가능한지 확인합니다.