클라우드 + DevOps/Kubernetes (k8s)

Kubernetes 실습 :: Kubernetes 대시보드 모니터링 실습 (2) 프로메테우스 모니터링 서비스 설치

gamjadori 2024. 4. 14. 13:24
728x90

<Prometheus>

컨테이너화된 환경에서 시스템 및 서비스 모니터링을 위한 오픈 소스 시스템

 

1. git에서 실습을 위한 monitoring 리소스 가져오기

  • 외부 리포지토리에서 원하는 디렉토리만 선택적으로 가져오는 작업 수행
  • sparse checkout을 통해 특정 디렉토리만 로컬에 유지
  • Sparse checkout: Git에서 리포지토리의 일부 파일 또는 디렉토리만 로컬에 체크아웃하는 기능
ubuntu@k8s-master:~$ git init monitoring
>> monitoring 저장소 생성
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch 
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m 
Initialized empty Git repository in /home/ubuntu/monitoring/.git/
ubuntu@k8s-master:~$ ls
2163         cd              Desktop    Downloads   Music     Public  snap       Videos
calico.yaml  dashboard_rbac  Documents  **monitoring**  Pictures  pwd     Templates
ubuntu@k8s-master:~$ cd monitoring/

ubuntu@k8s-master:~/monitoring$ git config --global init.defaultBranch main
>> 저장소를 초기화한 후, 기본 브랜치 이름
설정 ubuntu@k8s-master:~/monitoring$ git remote add -f origin <https://github.com/k8s-1pro/install.git> Updating origin >> Git 저장소에 원격 저장소 추가 remote: Enumerating objects: 944, done. remote: Counting objects: 100% (256/256), done. remote: Compressing objects: 100% (195/195), done. remote: Total 944 (delta 84), reused 220 (delta 57), pack-reused 688 Receiving objects: 100% (944/944), 628.75 KiB | 1.11 MiB/s, done. Resolving deltas: 100% (332/332), done. From <https://github.com/k8s-1pro/install> * [new branch] main -> origin/main
  • sparse checkout 활성화
  • origin 원격 저장소에서 로컬 브랜치에 병합
ubuntu@k8s-master:~/monitoring$ git config core.sparseCheckout true
ubuntu@k8s-master:~/monitoring$ echo "ground/k8s-1.27/prometheus-2.44.0" >> .git/info/sparse-checkout
ubuntu@k8s-master:~/monitoring$ echo "ground/k8s-1.27/loki-stack-2.6.1" >> .git/info/sparse-checkout
ubuntu@k8s-master:~/monitoring$ git pull origin main
From <https://github.com/k8s-1pro/install>
 * branch            main       -> FETCH_HEAD

 

2. 모니터링을 위한 리소스 서버에 생성 확인

3. 클러스터에 Prometheus와 Loki 배포

ubuntu@k8s-master:~/monitoring$ kubectl apply --server-side -f ground/k8s-1.27/prometheus-2.44.0/manifests/setup
ubuntu@k8s-master:~/monitoring$ kubectl wait --for condition=Established --all CustomResourceDefinition --namespace=monitoring
ubuntu@k8s-master:~/monitoring$ kubectl apply -f ground/k8s-1.27/prometheus-2.44.0/manifests
secret/grafana-config createdubuntu@k8s-master:~/monitoring$ kubectl apply -f ground/k8s-1.27/loki-stack-2.6.1
namespace/loki-stack created