我正在从终端运行以下命令,以检索所有名称空间中特定荚的状态。我试图解决的问题是只返回唯一的名称空间,该名称空间的状态为“被逐出”
kubectl get pods --all-namespaces -lapp=myapp | grep Evicted | sort | uniq -c--这是我得到的结果的一个例子:
NAMESPACE READY STATUS
customer-1 0/1 Evicted
customer-3 0/1 Evicted
customer-2 0/1 Evicted
customer-3 0/1 Evicted
customer-1 0/1 Evicted--这是我想要的结果:
NAMESPACE READY STATUS
customer-1 0/1 Evicted
customer-2 0/1 Evicted
customer-3 0/1 Evicted我怎样才能做到这一点呢?
发布于 2020-03-04 21:55:23
kubectl get pods --all-namespaces -lapp=myapp | grep Evicted | awk {'print $1'} | uniq -c应该为你做点什么。由于非唯一的荚名,Uniq没有产生效果。
发布于 2020-03-05 10:59:49
我建议您使用kubectl命令参数的另一种方法:
$ kubectl get pods --all-namespaces --field-selector=status.phase=Evicted --sort-by=.metadata.namespace -o custom-columns=NAMESPACE:.metadata.namespace | uniq这里我们使用一些参数来筛选、排序和定义自定义列输出。
输出将类似于以下内容:
NAMESPACE
customer-1
customer-2
customer-3https://stackoverflow.com/questions/60534466
复制相似问题