Grafana

[Helm] kube-prometheus-stack / Grafana Persistence 활성화

비번변경 2022. 5. 31. 18:07

쿠버네티스 클러스터 리소스의 모니터링 목적으로 Grafana와 Prometheus를 설치해서 사용하고 있다.

다만, 서버 장애 또는 업그레이드 시 데이터가 휘발되고 있어 확인해보니 persistence 설정이 되어 있지 않았다.

 

이 글에서는 kube-prometheus-stack helm chart를 이용해 Grafana Persistence 활성화하는 방법을 정리한다.

 

kube-prometheus-stack

kube-prometheus-stack logo

클러스터에 Grafana와 Prometheus를 한 번에 설치할 수 있는 helm chart

기존에는 prometheus-operator라는 이름으로 사용했다.

Github : kube-prometheus-stack

 

 

설치 방법

설치 방법을 간단히 정리한다.

 

1. helm chart 저장소 추가

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

 

2. kube-prometheus-stack chart 설치

helm install [RELEASE_NAME] prometheus-community/kube-prometheus-stack

 

 

Prometheus의 경우

prometheus는 수집한 데이터를 2시간 단위로 그룹화하여 디렉터리에 저장한다.

persistence를 활성화하지 않으면 pod container 내에 데이터가 저장되기 때문에 pod container의 수명주기와 데이터의  수명주기가 동일하게 된다. 즉, pod가 중지될 때마다 실행 시간에 수집한 모든 데이터가 휘발된다.

따라서 pod 중지에 상관없이 데이터를 유지하고 싶다면 values.yaml 파일을 이용해 persistence를 활성화해야 한다.

 

관련 설정은 values.yaml의 2440번째 줄에 있다.

## Deploy a Prometheus instance
##
prometheus:
  enabled: true
  
  ## Settings affecting prometheusSpec
  ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#prometheusspec
  ##
  prometheusSpec:
    ## Prometheus StorageSpec for persistent data
    ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/storage.md
    ##
    storageSpec: {}
    ## Using PersistentVolumeClaim
    ##
      volumeClaimTemplate:
        spec:
          storageClassName: gluster
          accessModes: ["ReadWriteOnce"]
          resources:
            requests:
              storage: 50Gi
    #    selector: {}

 

 

Grafana의 경우

Prometheus와 마찬가지로, Grafana 역시 persistence를 활성화하지 않으면 생성한 사용자, 생성한 대시보드 등의 정보 등이 pod가 중지될 때마다 휘발된다.

다만 kube-prometheus-stack의 values.yaml에는 grafana persistence 관련 설정이 보이지 않아 설정하기가 난감한 면이 있다.

하지만 kube-prometheus-stack이 의존하고 있는 grafana/grafanavalues.yaml 파일의 282번째 줄을 살펴보면 관련 설정이 존재하는 것을 확인할 수 있다.

## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
persistence:
  type: pvc
  enabled: false
  # storageClassName: default
  accessModes:
    - ReadWriteOnce
  size: 10Gi
  # annotations: {}
  finalizers:
    - kubernetes.io/pvc-protection
  # selectorLabels: {}
  ## Sub-directory of the PV to mount. Can be templated.
  # subPath: ""
  ## Name of an existing PVC. Can be templated.
  # existingClaim:

따라서 grafana/grafana의 values.yaml을 수정하거나 kube-prometheus-stack의 values.yaml을 통해 grafana/grafana chart에 설정을 전달하면 persistence를 활성화할 수 있다. kube-prometheus-stack의 values.yaml에 grafana.persistence 항목을 추가하면 된다.

vi /chart/path/kube-prometheus-stack/values.yaml

## Using default values from https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml
##
grafana:
  enabled: true
  
  # 아래 내용 추가
  persistence:
    enabled: true # true로 설정
    type: pvc
    storageClassName: k8s # 스토리지 클래스
    accessModes:
    - ReadWriteOnce
    size: 10Gi # 용량 설정
    finalizers:
    - kubernetes.io/pvc-protection

 

 

참고 문서

https://github.com/prometheus-community/helm-charts/issues/436

 

 

 

 

 

728x90