본문 바로가기
Compute/kubernetis

[따배씨] 13. CPU 사용량이 높은 Pod 검색 / CKA 시험 문제 학습

by 조청유곽 2025. 1. 31.
반응형

이 포스팅은 아래의 유튜브 채널 "따배"를 따라서 학습한 내용입니다. 

 

 

[관련 이론]


 

 

[Precondition]

(1) 테스트 환경

(1.1) Rocky Linux Cluster 

: 직접 구성

[root@k8s-master ~]# k get nodes -o wide
NAME         STATUS   ROLES           AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                            KERNEL-VERSION                  CONTAINER-RUNTIME
k8s-master   Ready    control-plane   30d   v1.27.2   192.168.56.30   <none>        Rocky Linux 8.10 (Green Obsidian)   4.18.0-553.33.1.el8_10.x86_64   containerd://1.6.32
k8s-node1    Ready    <none>          30d   v1.27.2   192.168.56.31   <none>        Rocky Linux 8.8 (Green Obsidian)    4.18.0-477.10.1.el8_8.x86_64    containerd://1.6.21
k8s-node2    Ready    <none>          30d   v1.27.2   192.168.56.32   <none>        Rocky Linux 8.8 (Green Obsidian)    4.18.0-477.10.1.el8_8.x86_64    containerd://1.6.21
[root@k8s-master ~]#

 

(1.2) Ubuntu Cluster 

: kodekloud 테스트 환경 활용

controlplane ~ ➜  kubectl get nodes -o wide
NAME           STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane   9m6s    v1.31.0   192.6.94.6    <none>        Ubuntu 22.04.4 LTS   5.4.0-1106-gcp   containerd://1.6.26
node01         Ready    <none>          8m31s   v1.31.0   192.6.94.9    <none>        Ubuntu 22.04.4 LTS   5.4.0-1106-gcp   containerd://1.6.26

https://learn.kodekloud.com/user/courses/udemy-labs-certified-kubernetes-administrator-with-practice-tests

 

(2) 사전 필요 설정 

-  테스트에 사용할 pod 다수개 생성

controlplane ~ ➜  cat 12-dep.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    name: overloaded-cpu
  name: cpuload
spec:
  replicas: 5
  selector:
    matchLabels:
      name: overloaded-cpu
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        name: overloaded-cpu
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

controlplane ~ ➜  k apply -f 12-dep.yaml 
deployment.apps/cpuload created

controlplane ~ ➜  k get pods --show-labels 
NAME                      READY   STATUS             RESTARTS        AGE   LABELS
cpuload-977774565-f6fs2   1/1     Running            0               8s    name=overloaded-cpu,pod-template-hash=977774565
cpuload-977774565-krr48   1/1     Running            0               8s    name=overloaded-cpu,pod-template-hash=977774565
cpuload-977774565-lmdm9   1/1     Running            0               8s    name=overloaded-cpu,pod-template-hash=977774565
cpuload-977774565-rf89x   1/1     Running            0               8s    name=overloaded-cpu,pod-template-hash=977774565
cpuload-977774565-skhl6   1/1     Running            0               8s    name=overloaded-cpu,pod-template-hash=977774565

 


 

 

[Question#2]

From the pod label name=overloaded-cpu, find pods running high CPU workloads and name of the pod consuming most CPU to the file /var/CKA2022/cpu_load_pod.txt

 

 

[Solve]

(1) pod label 확인 

[root@k8s-master ~]# k get pods --show-labels 
NAME                       READY   STATUS    RESTARTS   AGE   LABELS
cpuload-669c759d97-2f269   1/1     Running   0          50s   name=overloaded-cpu,pod-template-hash=669c759d97
cpuload-669c759d97-5qdkw   1/1     Running   0          50s   name=overloaded-cpu,pod-template-hash=669c759d97
cpuload-669c759d97-7dq4w   1/1     Running   0          50s   name=overloaded-cpu,pod-template-hash=669c759d97
cpuload-669c759d97-kxrhj   1/1     Running   0          50s   name=overloaded-cpu,pod-template-hash=669c759d97
cpuload-669c759d97-qhgl2   1/1     Running   0          50s   name=overloaded-cpu,pod-template-hash=669c759d97
[root@k8s-master ~]# 
[root@k8s-master ~]# k top pods --sort-by=cpu
NAME                       CPU(cores)   MEMORY(bytes)   
cpuload-669c759d97-2f269   0m           3Mi             
cpuload-669c759d97-5qdkw   0m           2Mi             
cpuload-669c759d97-7dq4w   0m           2Mi             
cpuload-669c759d97-kxrhj   0m           2Mi             
cpuload-669c759d97-qhgl2   0m           3Mi

 

 

(2) label을 가진 pod들을 cpu로 sorting

[root@k8s-master ~]# k top pods --sort-by=cpu -l name=overloaded-cpu
NAME                       CPU(cores)   MEMORY(bytes)   
cpuload-669c759d97-2f269   0m           3Mi             
cpuload-669c759d97-5qdkw   0m           2Mi             
cpuload-669c759d97-7dq4w   0m           2Mi             
cpuload-669c759d97-kxrhj   0m           2Mi             
cpuload-669c759d97-qhgl2   0m           3Mi             
[root@k8s-master ~]#

 

 

[사용 커맨드 정리]

- 생략 

반응형