26Z05d5

Young-Kyoo Kim·2026년 8월 4일

Prometheus UI 또는 Grafana 탐색기(Explore)에서 사용할 수 있는 CPU/Memory Request 상위 10개 Namespace 추출 PromQL 쿼리입니다.


CPU Request Top 10 Namespace

topk(10, sum(kube_pod_container_resource_requests{resource="cpu"}) by (namespace))
  • Multi-cluster 환경 (특정 클러스터 선택 시):
topk(10, sum(kube_pod_container_resource_requests{resource="cpu", cluster=~"$cluster"}) by (namespace))

Memory Request Top 10 Namespace

topk(10, sum(kube_pod_container_resource_requests{resource="memory"}) by (namespace))
  • Multi-cluster 환경 (특정 클러스터 선택 시):
topk(10, sum(kube_pod_container_resource_requests{resource="memory", cluster=~"$cluster"}) by (namespace))

kubectl CLI로 직접 확인하는 방법

Kubernetes 클러스터에 직접 명령어로 조회할 때는 kubectljq를 활용해 계산할 수 있습니다.

1. CPU Request 상위 10개 Namespace

kubectl get pods --all-namespaces -o json | jq -r '
  .items 
  | group_by(.metadata.namespace) 
  | map({
      namespace: .[0].metadata.namespace, 
      cpu_request: (map(.spec.containers[].resources.requests.cpu // "0" | if endsWith("m") then (trimstr("m") | tonumber / 1000) else tonumber end) | add)
    }) 
  | sort_by(.cpu_request) 
  | reverse 
  | .[:10] 
  | .[] | "\(.namespace)\t\(.cpu_request) Cores"' | column -t

2. Memory Request 상위 10개 Namespace

kubectl get pods --all-namespaces -o json | jq -r '
  .items 
  | group_by(.metadata.namespace) 
  | map({
      namespace: .[0].metadata.namespace, 
      mem_bytes: (map(.spec.containers[].resources.requests.memory // "0" | 
        if endsWith("Gi") then (trimstr("Gi") | tonumber * 1024 * 1024 * 1024)
        elif endsWith("Mi") then (trimstr("Mi") | tonumber * 1024 * 1024)
        elif endsWith("Ki") then (trimstr("Ki") | tonumber * 1024)
        elif endsWith("G") then (trimstr("G") | tonumber * 1000 * 1000 * 1000)
        elif endsWith("M") then (trimstr("M") | tonumber * 1000 * 1000)
        elif endsWith("K") then (trimstr("K") | tonumber * 1000)
        else tonumber end) | add)
    }) 
  | sort_by(.mem_bytes) 
  | reverse 
  | .[:10] 
  | .[] | "\(.namespace)\t\(.mem_bytes / 1024 / 1024 / 1024 | round) GiB"' | column -t

0개의 댓글