#!/bin/bash
echo "namespace,pod,container,request_cpu,limit_cpu,usage_cpu,request_mem,limit_mem,usage_mem" >> count.result
for ns in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do
#for pod in $(kubectl get pod -n $ns -o jsonpath='{.items[*].metadata.name}'); do
for pod in $(kubectl get pod -n $ns |grep Running|awk '{print $1}'); do
for container in $(kubectl get pod $pod -n $ns -o jsonpath='{.spec.containers[*].name}'); do
req_cpu=$(kubectl get pod $pod -n $ns -o jsonpath="{.spec.containers[?(@.name=='$container')].resources.requests.cpu}")
req_mem=$(kubectl get pod $pod -n $ns -o jsonpath="{.spec.containers[?(@.name=='$container')].resources.requests.memory}")
lim_cpu=$(kubectl get pod $pod -n $ns -o jsonpath="{.spec.containers[?(@.name=='$container')].resources.limits.cpu}")
lim_mem=$(kubectl get pod $pod -n $ns -o jsonpath="{.spec.containers[?(@.name=='$container')].resources.limits.memory}")
usage_cpu=$(kubectl top pod $pod -n $ns --containers=true --no-headers | awk '{print $3}' | awk '{s+=$1} END {print s}')
usage_mem=$(kubectl top pod $pod -n $ns --containers=true --no-headers | awk '{print $4}' | awk '{s+=$1} END {print s}')
if [[ "$req_cpu" != "" && "$req_mem" != "" && "$lim_cpu" != "" && "$lim_mem" != "" ]]; then
echo "$ns,$pod,$container,$req_cpu,$lim_cpu,$usage_cpu,$req_mem,$lim_mem,$usage_mem" >> count.result
fi
done
done
done
文章来源地址https://www.toymoban.com/news/detail-555587.html
文章来源:https://www.toymoban.com/news/detail-555587.html
到了这里,关于k8s集群统计实际pod request、limit、实际资源使用率的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!