Logging & Monitoring

zuckerfrei·2024년 1월 1일
0

Kubernetes

목록 보기
27/63

1. Cluster Monitoring

Metrics Server로 k8s 클러스터 모니터링하기

minikube

minikube addons enable metrics-server

others

1) metrics server 관련 스크립트 다운로드

git clone https://github.com/kubernetes-incubator/metrics-server.git
# 예시 - 실제 업무에서는 이 github repo 경로를 사용하지 말 것
controlplane ~ ➜  git clone https://github.com/kodekloudhub/kubernetes-metrics-server.git
Cloning into 'kubernetes-metrics-server'...
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 31 (delta 8), reused 0 (delta 0), pack-reused 12
Unpacking objects: 100% (31/31), 8.06 KiB | 1.15 MiB/s, done.

controlplane kubernetes-metrics-server on  master ➜  ls
aggregated-metrics-reader.yaml  auth-reader.yaml         metrics-server-deployment.yaml  README.md
auth-delegator.yaml             metrics-apiservice.yaml  metrics-server-service.yaml     resource-reader.yaml

2) metrics server 생성(설치)

kubectl create -f {파일}
# 예시
controlplane kubernetes-metrics-server on  master ➜  kubectl create -f . 
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
    clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
deployment.apps/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created

3) 모니터링하기

kubectl top node
kubectl top pod
# 예시
controlplane kubernetes-metrics-server on  master ➜  kubectl top node
NAME           CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
controlplane   206m         0%     1149Mi          0%        
node01         26m          0%     289Mi           0%

controlplane kubernetes-metrics-server on  master ➜  kubectl top pod
NAME       CPU(cores)   MEMORY(bytes)   
elephant   15m          32Mi            
lion       1m           17Mi            
rabbit     105m         252Mi

2. Application Monitoring

k8s에서 애플리케이션 모니터링은 도커와 거의 유사함

pod 로그 모니터링

kubectl logs -f {pod이름}
# 예시
controlplane ~ ➜  kubectl logs -f webapp-1 
[2024-01-01 12:19:44,681] INFO in event-simulator: USER1 is viewing page2
[2024-01-01 12:19:45,682] INFO in event-simulator: USER2 logged in
[2024-01-01 12:19:46,683] INFO in event-simulator: USER2 is viewing page2
[2024-01-01 12:19:47,683] INFO in event-simulator: USER4 logged in
[2024-01-01 12:19:48,684] INFO in event-simulator: USER4 logged out
[2024-01-01 12:19:49,685] WARNING in event-simulator: USER5 Failed to Login as the account is locked due to MANY FAILED ATTEMPTS.

pod는 다중 컨테이너로 구성될 수 있음
만약 여러 컨테이너로 구성된 pod 에서 특정한 컨테이너 하나의 로그를 확인하려면

kubectl logs -f {pod이름} {컨테이너이름}
profile
무설탕 음료를 좋아합니다

0개의 댓글