查看每个节点的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)
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐