Docker, k8s

k8s_helm Prometheus Grafana 연동

우당탕탕인생기 2023. 9. 15. 17:18

k8s을 통해서 Promethus Grafans 연동을 통해 Resource을 모니터링 하는 작업을 해보려고한다.

 

우선, 리눅스의 yum 과같은 k8s package 관리을 해주는 Helm을 설치해야한다.

자세한 내용은 아래에 코드로 잘 정리되어 있다.

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

 

헬름 설치하기

헬름 설치하고 작동하는 방법 배우기.

helm.sh

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

helm repo add stable https://charts.helm.sh/stable  # 레포지토리 추가

helm repo update  #레포지토리 업데이트

Prometheus package 설치

 

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

helm install prometheus-community/kube-prometheus-stack --generate-name

kubectl get pods,svc,deployment,secret -o wide # 해당 deploy와 service가 잘 실행되는지 확인

 

외부 노출(Service)

확인이 됐으면, 외부로 서비스 하기 위해서 포트를 ClusterIP가 아닌 NodePort을 사용해야 한다.

 

kubectl edit service/kube-prometheus-stack-1694762545-grafana

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
    - 중략 
  type: NodePort  # 이 부분을 노드포트로 변경해준다.
status:
  loadBalancer: {}
~

비밀번호 확인

이제 접속을 위한 비밀번호를 확인해야 하는데 현재 암호화 되어 있기 때문에, decode을 해서 확인해줘야 한다.

kubectl get kube-prometheus-stack-1694762545-grafana -o jsonpath="{.data.admin-password}" | base64 --decode;echo

 

이후 현재 k8s 에서 서비스 중인것을 확인하여  k8s을 실행중인 ip:포트번호를 입력한 이후 아이디는 admin , 비밀번호는 decode된 비밀빈호를 입력하면된다.

대시보드 탭에서 k8s Compute resources / Namespace(Pod) 을 클릭하면

이렇게 화면이 잘 구성된 것이 보인다.

 

 

'Docker, k8s' 카테고리의 다른 글

k8s_Volume (1) EmptyDir , hostPath  (0) 2023.09.16
k8s_ Ingress nginx  (0) 2023.09.15
k8s_ Replica, Depolyment  (0) 2023.09.13
k8s_yml 파일을 통한 Pod 실행  (0) 2023.09.13
k8s_ Pod 생성, Pod접속 , Service, Namespace  (0) 2023.09.12