EKS에 Helm으로 Prometheus 설치하기

brillog·2024년 1월 14일
0

DevOps

목록 보기
7/7

Prerequisites

  1. EBS CSI Driver 애드온 생성
    EBS 사용을 위해 'EBS CSI Driver 애드온' 생성이 필요합니다. EBS CSI Driver 애드온 생성은 eksctl로 EKS Addon 생성하기(EBS CSI Driver 애드온 생성)를 참고해 주세요.
    EBS CSI Driver 애드온
  2. Helm V3 설치
    Helm chart를 사용하여 EKS 클러스터에 Prometheus를 배포해 보겠습니다. 그러기 위해선 helm V3 이상을 사용하여야 합니다.
    $ helm version
    version.BuildInfo{Version:"v3.8.2", GitCommit:"6e3701edea09e5d55a8ca2aae03a68917630e91b", GitTreeState:"clean", GoVersion:"go1.17.5"}

Prometheus 설치

  1. (optional) 네임스페이스 생성

    # 'prometheus' 네임스페이스 생성
    $ kubectl create ns monitoring
    
    # 'prometheus' 네임스페이스로 current context 변경
    $ kubectl config set-context --current --namespace=monitoring
  2. Prometheus Repository 추가

    # 'prometheus-community' repo 추가
    $ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    "prometheus-community" has been added to your repositories
    
    # repo가 추가되었는지 확인
    $ helm repo list
    NAME                    URL                                             
    prometheus-community    https://prometheus-community.github.io/helm-charts
    ...
    
    # 최신 차트가 적용되도록 local repository를 업데이트
    $ helm repo update prometheus-community
    ...Successfully got an update from the "prometheus-community" chart repository
    Update Complete. ⎈Happy Helming!
  3. values.yaml 파일 수정을 위해 helm chart 다운로드

    git clone https://github.com/prometheus-community/helm-charts.git
  4. values.yaml 파일 수정
    ingress 사용을 위해 다운로드 한 value.yaml 파일의 Service type을 ClusterIP에서 NodePort로 수정

    $ vi .../helm-charts/charts/prometheus/values.yaml
      ...
      service:
        enabled: true  ## If false, no Service will be created for the Prometheus server
        annotations: {}
        labels: {}
        clusterIP: ""
        externalIPs: []  ## List of IP addresses at which the Prometheus server service is available (Ref: https://kubernetes.io/docs/concepts/services-networking/service/#external-ips)
        loadBalancerIP: ""
        loadBalancerSourceRanges: []
        servicePort: 80
        sessionAffinity: None
        type: NodePort  # ClusterIP -> NodePort로 변경
      ...
  5. 수정한 value.yaml 파일을 적용하여 helm install

    $ helm install prometheus prometheus-community/prometheus -f values.yaml
  6. 생성된 리소스 확인

    $ kubectl get all
    NAME                                                 READY   STATUS    RESTARTS   AGE
    prometheus-alertmanager-0                            1/1     Running   0          37m
    prometheus-kube-state-metrics-7748c67656-xwl5q       1/1     Running   0          142m
    prometheus-prometheus-node-exporter-4r9kr            1/1     Running   0          142m
    prometheus-prometheus-node-exporter-h9kmd            1/1     Running   0          142m
    prometheus-prometheus-node-exporter-s5lg5            1/1     Running   0          138m
    prometheus-prometheus-node-exporter-xj9lm            1/1     Running   0          138m
    prometheus-prometheus-pushgateway-8457c6cff7-pg546   1/1     Running   0          142m
    prometheus-server-799f594896-ncd9x                   2/2     Running   0          125m
    ...
  1. ingress 생성

    ingress 설정을 위한 사전 작업은 EKS에 Helm으로 AWS Load Balancer Controller 설치하기를 참고해 주세요.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: ingress-monitoring
      annotations:
        kubernetes.io/ingress.class: alb
        alb.ingress.kubernetes.io/scheme: internet-facing
        alb.ingress.kubernetes.io/target-type: instance
        alb.ingress.kubernetes.io/load-balancer-name: <생성할_LB_NAME>
        alb.ingress.kubernetes.io/subnets: <SUBNET_ID_1>,<SUBNET_ID_2>
        alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:<REGION-CODE>:<ACCOUNT_ID>:certificate/<CERTIFICATE_ID>
        alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
        alb.ingress.kubernetes.io/ssl-redirect: '443'
    spec:
      rules:
        - host: prometheus.mytestdomain.com
          http:
            paths:
              - pathType: Prefix
                path: /
                backend:
                  service:
                    name: prometheus-server
                    port:
                      number: 80

    7-1. 생성된 prometheus Target group의 Health check Path를 /-/healthy로 변경

    7-2. Route53에서 prometheus.mytestdomain.com(ingress에 rules 설정한 host)을 ingress LB 도메인으로 설정 (도메인을 Route53에서 구입했다고 가정)

  2. 웹브라우저에서 prometheus.mytestdomain.com 접속 확인
    Prometheus


Reference

개인적으로 공부하며 작성한 글로, 내용에 오류가 있을 수 있습니다.

profile
클라우드 엔지니어 ♡

0개의 댓글