EKS prometheus and grafana 설치하기

목표

  • EKS Cluster를 만든다
  • prometheus-grafana를 install한다
  • grafana를 실행한다

 

선행 프로그램 설치

eks cluster를 만들기 위해서는 다음과 같이 4가지 install이 선행되어야 한다.

윈도우 기준으로 install하겠다. 

 

package 관리 tool은 choco를 설치 해야한다.

https://chocolatey.org/install#individual

windows power shell을 administrator 모드로 실행 한다. (마우스 우측 관리자 권한으로 실행)

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

위의 코드를 붙여넣기 하고 실행한다.

$ choco
Chocolatey v0.10.15
Please run 'choco -?' or 'choco <command> -?' for help menu.

위 처럼 나오면 된다.

 

aws-cli install하기

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

https://awscli.amazonaws.com/AWSCLIV2.msi

을 다운로드 받아서 install 한다

C:\> aws --version

aws-cli/2.4.5 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

이 정상적으로 실행되면 된다.

aws configure를 통해서 사용자를 등록하면 된다.

$ aws configure

이러기 위해서는 IAM User를 등록하고 마지막에 나오는 access key와 secret key를 등록해야한다.

기본적으로 AdministratorAccess 권한이 있는 User가 필요하다.

Cluster가 만들어진 이후에는 EKS 권한만 필요한데, Cluster를 만들기 위해서는 Admin이 필요하다.

사용자 등록이 완료 되었으면

$ aws sts get-caller-identity
{
    "UserId": "AIDASDQFCH6DBX2IL7Y5B",
    "Account": "144965779334",
    "Arn": "arn:aws:iam::144965779334:user/Admin"
}

이렇게 현재 사용자의 user 정보를 알수 있다.

 

kubectl을 설치한다

https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/

choco를 통해서 install하면 된다.

choco install kubernetes-cli
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.5-eks-bc4871b", GitCommit:"5236faf39f1b7a7dabea8df12726f25608131aa9", GitTreeState:"clean", BuildDate:"2021-10-29T23:32:16Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}

이렇게 나오면 된다.

 

Eksctl 설치

해당 프로그램을 설치하기 전에 eksctl이 설치 되어있는지 확인해 보자.

(aws cli 설치하면 같이 설치 되었던거 같은데 기억이 정확하지 않다)

$ eksctl version
0.82.0

만약에 위에처럼 eksctl이 없다면

https://docs.aws.amazon.com/ko_kr/ko_kr/emr/latest/EMR-on-EKS-DevelopmentGuide/setting-up-eksctl.html

chocolatey install -y eksctl

을 사용해서 설치하자. 

 

Helm을 설치한다

https://helm.sh/docs/intro/install/

 

Installing Helm

Learn how to install and get running with Helm.

helm.sh

나는 cygwin을 사용하였음으로 windows install이 필요하다

choco install kubernetes-helm
$ helm version
version.BuildInfo{Version:"v3.7.2", GitCommit:"663a896f4a815053445eec4153677ddc24a0a361", GitTreeState:"clean", GoVersion:"go1.16.10"}

이렇게 나오면 된다.

 

eks cluster 생성하기

$ eksctl create cluster --name prometheus-grafana-cluster

위와 같이 cluster를 생성하면 하기와 같이 cluster를 생성한다.

참고로 default로 cluster를 실행하면 kubernetes api가 public으로 공개 된다.

2022-02-06 22:46:02 [ℹ]  eksctl version 0.82.0
2022-02-06 22:46:02 [ℹ]  using region us-east-2
2022-02-06 22:46:03 [ℹ]  setting availability zones to [us-east-2c us-east-2a us-east-2b]
2022-02-06 22:46:03 [ℹ]  subnets for us-east-2c - public:192.168.0.0/19 private:192.168.96.0/19
2022-02-06 22:46:03 [ℹ]  subnets for us-east-2a - public:192.168.32.0/19 private:192.168.128.0/19
2022-02-06 22:46:03 [ℹ]  subnets for us-east-2b - public:192.168.64.0/19 private:192.168.160.0/19
2022-02-06 22:46:03 [ℹ]  nodegroup "ng-e158f753" will use "" [AmazonLinux2/1.21]
2022-02-06 22:46:03 [ℹ]  using Kubernetes version 1.21
2022-02-06 22:46:03 [ℹ]  creating EKS cluster "prometheus-grafana-cluster" in "us-east-2" region with managed nodes
2022-02-06 22:46:03 [ℹ]  will create 2 separate CloudFormation stacks for cluster itself and the initial managed nodegroup
2022-02-06 22:46:03 [ℹ]  if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=us-east-2 --cluster=prometheus-grafana-cluster'
2022-02-06 22:46:03 [ℹ]  Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "prometheus-grafana-cluster" in "us-east-2"
2022-02-06 22:46:03 [ℹ]  CloudWatch logging will not be enabled for cluster "prometheus-grafana-cluster" in "us-east-2"
2022-02-06 22:46:03 [ℹ]  you can enable it with 'eksctl utils update-cluster-logging --enable-types={SPECIFY-YOUR-LOG-TYPES-HERE (e.g. all)} --region=us-east-2 --cluster=prometheus-grafana-cluster'    
2022-02-06 22:46:03 [ℹ]
2 sequential tasks: { create cluster control plane "prometheus-grafana-cluster",
    2 sequential sub-tasks: {
        wait for control plane to become ready,
        create managed nodegroup "ng-e158f753",
    }
2022-02-06 23:04:56 [✔]  saved kubeconfig as "C:\\cygwin64\\home\\home\\.kube\\config"
2022-02-06 23:04:56 [ℹ]  no tasks
2022-02-06 23:04:56 [✔]  all EKS cluster resources for "prometheus-grafana-cluster" have been created
2022-02-06 23:04:57 [ℹ]  nodegroup "ng-e158f753" has 2 node(s)
2022-02-06 23:04:57 [ℹ]  node "ip-192-168-7-247.us-east-2.compute.internal" is ready
2022-02-06 23:04:57 [ℹ]  node "ip-192-168-87-103.us-east-2.compute.internal" is ready
2022-02-06 23:04:57 [ℹ]  waiting for at least 2 node(s) to become ready in "ng-e158f753"
2022-02-06 23:04:57 [ℹ]  nodegroup "ng-e158f753" has 2 node(s)
2022-02-06 23:04:57 [ℹ]  node "ip-192-168-7-247.us-east-2.compute.internal" is ready
2022-02-06 23:04:57 [ℹ]  node "ip-192-168-87-103.us-east-2.compute.internal" is ready
2022-02-06 23:05:00 [ℹ]  kubectl command should work with "C:\\cygwin64\\home\\home\\.kube\\config", try 'kubectl get nodes'
2022-02-06 23:05:00 [✔]  EKS cluster "prometheus-grafana-cluster" in "us-east-2" region is ready

만약에 권한이 없다고 나오면 IAM User의 권한이 AdministratorAccess 가 있는지 확인하자.

Cluster를 만들때 Cloudformation을 사용해야 해서 사실상 Admin 권한이 필요하다.

cluster가 다 생성이 되었다면 'eksctl get cluster'와 'kubectl get nodes'로 잘 만들어 졌는지 확인 가능하다.

$ eksctl get cluster
2022-03-20 18:36:32 [ℹ]  eksctl version 0.82.0
2022-03-20 18:36:32 [ℹ]  using region us-east-2
NAME            REGION          EKSCTL CREATED
eksctl-demo     us-east-2       True
$ kubectl get nodes
NAME                                           STATUS   ROLES    AGE     VERSION
ip-192-168-38-154.us-east-2.compute.internal   Ready    <none>   2m48s   v1.21.5-eks-9017834
ip-192-168-76-219.us-east-2.compute.internal   Ready    <none>   2m49s   v1.21.5-eks-9017834

 

위에 까지 확인이 되었다면

$ aws eks --region us-east-2 update-kubeconfig --name prometheus-grafana-cluster
Updated context arn:aws:eks:us-east-2:144965779334:cluster/prometheus-grafana-cluster in C:\Users\home\.kube\config

를 실행해 주자. kubeconfig에 방금 생성된 cluster 정보를 업데이트 시켜주는 명령어이다.

namespace로 monitoring을 생성해 주자.

$ kubectl create namespace monitoring
namespace/monitoring created

 

 

helm으로 prometheus & grafana를 설치하자.

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

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

상기 명령어를 통해서 repo를 helm에 등록해 준다.

$ helm repo update

repository  정보를 update해준다.

여기서 바로 install을 진행해도 되지만 무슨 사유인지 values.yaml을 별도로 정해줘야지 작동이 잘되었다. 그래서

https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml

여기있는 파일을 values.yaml 파일로 복사해서 helm 명령어가 실행될 위치에다 copy해주자.

$ helm install prometheus prometheus-community/kube-prometheus-stack -f "values.yaml" --namespace monitoring

이렇게 실행을 하면

NAME: prometheus
LAST DEPLOYED: Sun Feb  6 23:08:03 2022
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
  kubectl --namespace monitoring get pods -l "release=prometheus"

Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.

위와 같이 나오면 정상이다.

$ kubectl --namespace monitoring get pods -l "release=prometheus"
NAME                                                   READY   STATUS    RESTARTS   AGE
prometheus-kube-prometheus-operator-6cd54566dc-bppj2   1/1     Running   0          107s
prometheus-kube-state-metrics-66c645dc8c-77c4g         1/1     Running   0          107s
prometheus-prometheus-node-exporter-g64v8              1/1     Running   0          107s
prometheus-prometheus-node-exporter-hxbht              1/1     Running   0          107s

관련 pods가 정상적으로 작동함을 확인할 수 있다.

 

grafana가 실행되는 것을 확인하자

$ kubectl port-forward service/prometheus-grafana 3000:80 --namespace monitoring

grafana의 포트를 80번에서 local 컴퓨터 3000포트로 변경해 주자.

Forwarding from 127.0.0.1:3000 -> 3000
Forwarding from [::1]:3000 -> 3000
Handling connection for 3000
Handling connection for 3000
Handling connection for 3000
Handling connection for 3000
Handling connection for 3000
Handling connection for 3000
Handling connection for 3000

이렇게 나오면 local computer 3000번 포트로 데이터를 port-forward 한다는 의미이다.

이제 브라우저를 열어서 확인해 보자.

http://127.0.0.1:3000

을 브라우저에 작성하면 된다.

eks grafana

id는 admin

pw는 prom-operator

이다

efs grafana dashbaord

 

삭제는 필수다

https://docs.aws.amazon.com/eks/latest/userguide/delete-cluster.html

$ eksctl delete cluster --name prometheus-grafana-cluster

eks는 시간당 돈이 나간다. 꼭 삭제해 주자.

728x90
반응형