查看k8s每个节点/命名空间的pod数量
查看每个节点的pod数量(python脚本)# -*- coding: utf-8 -*-import commandsstatus, output = commands.getstatusoutput("kubectl get node")lines = output.split("\n")node = {}no...
·
查看每个节点的pod数量(python脚本)
# -*- coding: utf-8 -*-
import commands
status, output = commands.getstatusoutput("kubectl get node")
lines = output.split("\n")
node = {}
node['<none>'] = 0
for i in range(0, len(lines)):
no = lines[i].split()[0]
if no == "NAME":
continue
node[lines[i].split()[0]] = 0
status, output = commands.getstatusoutput("kubectl get po --all-namespaces -o wide")
lines = output.split("\n")
for i in range(0, len(lines)):
no = lines[i].split()[7]
if no == "NODE":
continue
node[lines[i].split()[7]] = node[lines[i].split()[7]] + 1
for k, v in node.items():
print(k, v)
查看每个nanmespace的pod数量(python脚本)
# -*- coding: utf-8 -*-
import commands
status,output = commands.getstatusoutput("kubectl get ns")
lines = output.split("\n")
namespaces={}
for i in range(0, len(lines)):
ns = lines[i].split()[0]
if ns == "NAME":
continue
namespaces[lines[i].split()[0]] = 0
status, output = commands.getstatusoutput("kubectl get po --all-namespaces")
lines = output.split("\n")
for i in range(0, len(lines)):
ns = lines[i].split()[0]
if ns =="NAMESPACE":
continue
namespaces[ns] = namespaces[ns] + 1
for k,v in namespaces.items():
print(k,v)
更多推荐
已为社区贡献6条内容
所有评论(0)