#!/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
文章來源地址http://www.zghlxwxcb.cn/news/detail-555587.html
文章來源:http://www.zghlxwxcb.cn/news/detail-555587.html
到了這里,關(guān)于k8s集群統(tǒng)計實際pod request、limit、實際資源使用率的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!