26Z28b

QK·2026년 8월 28일
kubectl get pods -A -o json | jq -r '
  def parse_cpu:
    if . == null then 0
    elif endswith("m") then (.[0:-1] | tonumber)
    else ((. | tonumber) * 1000) end;
  def parse_mem:
    if . == null then 0
    elif endswith("Ki") then (.[0:-2] | tonumber / 1024)
    elif endswith("Mi") then (.[0:-2] | tonumber)
    elif endswith("Gi") then (.[0:-2] | tonumber * 1024)
    else (.|tonumber / 1024 / 1024) end;

  [ .items[] | select(.status.phase=="Running") | {
      ns: .metadata.namespace,
      cpu: ([.spec.containers[].resources.requests.cpu] | map(parse_cpu) | add // 0),
      mem: ([.spec.containers[].resources.requests.memory] | map(parse_mem) | add // 0)
  } ]
  | group_by(.ns)
  | map({
      Namespace: .[0].ns,
      "CPU_Req(Cores)": ((map(.cpu) | add) / 1000),
      "Mem_Req(MiB)": (map(.mem) | add | round)
    })
'
profile
engineer

0개의 댓글