ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • EKS에 그라파나 + 프로메테우스 구성하기
    k8s 2023. 12. 21. 11:08

    아래 기재된 EKS 설정 이후에 작업한 내용입니다. 기본적인 EKS 셋팅은 아래 블로그 확인 부탁드리겠습니다.

    2023.12.20 - [k8s] - tfcloud 를 통한 EKS Terraform 설정

     

    프로메테우스 설치


    https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/prometheus.html

     

    Prometheus 지표 - Amazon EKS

    Prometheus 지표 Amazon Managed Service for Prometheus는 AWS GovCloud(미국 동부) 및 AWS GovCloud(미국 서부)에서 사용할 수 없습니다. Prometheus는 엔드포인트를 스크레이프하는 모니터링 및 시계열 데이터베이스입

    docs.aws.amazon.com

    위 사이트를 참고해 프로메테우스를 설치했다.

     

    Helm 사용을 통한 Prometheus 배포

    #prometheus 네임스페이스를 생성
    kubectl create namespace prometheus
    #prometheus-community 차트 리포지토리를 추가합니다
    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    #Prometheus를 배포합니다.
    helm upgrade -i prometheus prometheus-community/prometheus \
        --namespace prometheus \
        --set alertmanager.persistentVolume.storageClass="gp2",server.persistentVolume.storageClass="gp2"
    #kubectl get pods -n prometheus 네임스페이스 확인 모든 Pods가 Ready 상태인지 확인
    
     kubectl get pods -n prometheus
    
    NAME                                                 READY   STATUS    RESTARTS   AGE
    prometheus-alertmanager-0                            1/1     Running   0          28m
    prometheus-kube-state-metrics-85596bfdb6-pc7zd       1/1     Running   0          28m
    prometheus-prometheus-node-exporter-pmwxl            1/1     Running   0          28m
    prometheus-prometheus-node-exporter-rtwsc            1/1     Running   0          28m
    prometheus-prometheus-node-exporter-sxgll            1/1     Running   0          28m
    prometheus-prometheus-pushgateway-79745d4495-568vt   1/1     Running   0          28m
    prometheus-server-5f8f75bd86-z7mxt                   2/2     Running   0          28m

    prometheus-server.yaml파일 내용이다 참고만 하자

    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        meta.helm.sh/release-name: prometheus
        meta.helm.sh/release-namespace: prometheus
      creationTimestamp: "2023-12-20T06:39:25Z"
      labels:
        app.kubernetes.io/component: server
        app.kubernetes.io/instance: prometheus
        app.kubernetes.io/managed-by: Helm
        app.kubernetes.io/name: prometheus
        app.kubernetes.io/part-of: prometheus
        app.kubernetes.io/version: v2.48.1
        helm.sh/chart: prometheus-25.8.2
      name: prometheus-server
      namespace: prometheus
      resourceVersion: "43650"
      uid: f44b0fd2-207c-435f-a8f8-326a6dea3ca4
    spec:
      clusterIP: 172.20.34.186
      clusterIPs:
      - 172.20.34.186
      internalTrafficPolicy: Cluster
      ipFamilies:
      - IPv4
      ipFamilyPolicy: SingleStack
      ports:
      - name: http
        port: 80
        protocol: TCP
        targetPort: 9090
      selector:
        app.kubernetes.io/component: server
        app.kubernetes.io/instance: prometheus
        app.kubernetes.io/name: prometheus
      sessionAffinity: None
      type: ClusterIP
    status:
      loadBalancer: {}

     

    그라파나 설치


    https://grafana.com/docs/grafana/latest/setup-grafana/installation/kubernetes/

    위 사이트를 참고해 그라파나 설치

     

    grafana.yaml

    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: grafana-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: grafana
      name: grafana
    spec:
      selector:
        matchLabels:
          app: grafana
      template:
        metadata:
          labels:
            app: grafana
        spec:
          securityContext:
            fsGroup: 472
            supplementalGroups:
              - 0
          containers:
            - name: grafana
              image: grafana/grafana:latest
              imagePullPolicy: IfNotPresent
              ports:
                - containerPort: 3000
                  name: http-grafana
                  protocol: TCP
              readinessProbe:
                failureThreshold: 3
                httpGet:
                  path: /robots.txt
                  port: 3000
                  scheme: HTTP
                initialDelaySeconds: 10
                periodSeconds: 30
                successThreshold: 1
                timeoutSeconds: 2
              livenessProbe:
                failureThreshold: 3
                initialDelaySeconds: 30
                periodSeconds: 10
                successThreshold: 1
                tcpSocket:
                  port: 3000
                timeoutSeconds: 1
              resources:
                requests:
                  cpu: 250m
                  memory: 750Mi
              volumeMounts:
                - mountPath: /var/lib/grafana
                  name: grafana-pv
          volumes:
            - name: grafana-pv
              persistentVolumeClaim:
                claimName: grafana-pvc
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: grafana
    spec:
      ports:
        - port: 3000
          protocol: TCP
          targetPort: http-grafana
      selector:
        app: grafana
      sessionAffinity: None
      type: LoadBalancer

     

    k apply -f grafana.yaml

    설치가 잘되어있는지 확인

     k get svc
    NAME         TYPE           CLUSTER-IP      EXTERNAL-IP                                                                    PORT(S)          AGE
    grafana      LoadBalancer   172.20.104.14   a2cf93e65450****   3000:30952/TCP   49m

    그라파나 접속

    http://<EXTERNAL-IP>:<PORT>

    위 주소로 접속하면 로그인 화면이 보인다. 아이디 패스워드는 admin/admin

    로그인을 한 후 가장 처음 할 일은 Data source를 지정하는 것이다. 우리는 prometheus를 이용할 것이다.

    URL은 서비스이름.네임스페이스.svc:port로 작성하면 된다.

     

    위 명령어로 확인한 URL은 아래 처럼 작성하면 된다.

    http://prometheus-server.prometheus.svc:80

    save & test 눌러서 잘되는지 확인한 후 dashboard를 import하자

    Import a dashboard를 누르면 아래 화면이 나온다.

    나는 한국분이 만드신 13770 대시보드를 이용

    Grafana.com dashboard URL or ID부분에 13770을 입력하고 Load 버튼을 누른다음 아래 DataSource를 Prometheus로 설정해주면 된다.

     

    pvc 3개

     k get pvc -A
    NAMESPACE    NAME                                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    default      grafana-pvc                         Bound    pvc-ab485acb-162c-4e49-85a8-8feb17ce49c8   1Gi        RWO            gp2            63m
    prometheus   prometheus-server                   Bound    pvc-c2892ffb-5a59-4bf2-bab1-e658df28bddc   8Gi        RWO            gp2            44m
    prometheus   storage-prometheus-alertmanager-0   Bound    pvc-bf9f889a-13b4-4c81-95f6-db720326ed6d   2Gi        RWO            gp2            44m

     

    네임스페이스 5개

     k get namespaces -A
    NAME              STATUS   AGE
    default           Active   4h17m
    kube-node-lease   Active   4h17m
    kube-public       Active   4h17m
    kube-system       Active   4h17m
    prometheus        Active   45m

     

    Pods 21개

     k get pods -A
    NAMESPACE     NAME                                                 READY   STATUS    RESTARTS   AGE
    default       grafana-684d8b87db-6rgdt                             1/1     Running   0          64m
    kube-system   aws-node-lkppj                                       1/1     Running   0          4h13m
    kube-system   aws-node-nt2c9                                       1/1     Running   0          4h13m
    kube-system   aws-node-xnk5d                                       1/1     Running   0          4h13m
    kube-system   coredns-6d47776b78-clzcv                             1/1     Running   0          4h17m
    kube-system   coredns-6d47776b78-rx9pw                             1/1     Running   0          4h17m
    kube-system   ebs-csi-controller-65ff7f6d7-hj6h6                   6/6     Running   0          4h14m
    kube-system   ebs-csi-controller-65ff7f6d7-tsc7c                   6/6     Running   0          4h14m
    kube-system   ebs-csi-node-6km75                                   3/3     Running   0          4h13m
    kube-system   ebs-csi-node-jqf9q                                   3/3     Running   0          4h13m
    kube-system   ebs-csi-node-xdv2l                                   3/3     Running   0          4h13m
    kube-system   kube-proxy-p6gwz                                     1/1     Running   0          4h13m
    kube-system   kube-proxy-wcr9p                                     1/1     Running   0          4h13m
    kube-system   kube-proxy-x4n7g                                     1/1     Running   0          4h13m
    prometheus    prometheus-alertmanager-0                            1/1     Running   0          45m
    prometheus    prometheus-kube-state-metrics-85596bfdb6-pc7zd       1/1     Running   0          45m
    prometheus    prometheus-prometheus-node-exporter-pmwxl            1/1     Running   0          45m
    prometheus    prometheus-prometheus-node-exporter-rtwsc            1/1     Running   0          45m
    prometheus    prometheus-prometheus-node-exporter-sxgll            1/1     Running   0          45m
    prometheus    prometheus-prometheus-pushgateway-79745d4495-568vt   1/1     Running   0          45m
    prometheus    prometheus-server-5f8f75bd86-z7mxt                   2/2     Running   0          45m

     

    마무리


    모니터링에 대해서 조금 더 공부해야되지만 우선 노드 목록이 나오고 네임스페이스 및 pods 확인 결과 일치하기에 우선은 설치는 제대로 된 것 같다.

    프로젝트를 하기전 테스트로 진행해본 것 모니터링에 대해서는 앞으로 다시 공부 할 생각입니다.

    'k8s' 카테고리의 다른 글

    Kubernetes Architecture, Cluster Nodes  (0) 2024.01.04
    Kubernetes Architecture, Control Plane  (1) 2024.01.03
    tfcloud 를 통한 EKS Terraform 설정  (0) 2023.12.20
    로컬 서버에 Longhorn구축  (1) 2023.12.07
    쿠버네티스 기초용어  (1) 2023.12.06
Designed by Tistory.