gpt4 book ai didi

kubernetes - 从 kubectl 输出显示失败的 pod

转载 作者:行者123 更新时间:2023-12-02 11:52:07 25 4
gpt4 key购买 nike

我想在 kubectl 上写一个包装器只显示失败的 pod,这意味着它应该只显示 Ready 列值不同的项目(即 0/1, 0/2, 1/2, 2/3, 等)

$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default pod-with-sidecar 1/2 ErrImagePull 0 39s
kube-system calico-node-chcqq 2/2 Running 2 7d
kube-system calico-policy-controller-6449789dd6-z5t5j 1/1 Running 0 7d
kube-system etcd 1/1 Running 0 7d
kube-system kube-apiserver 1/1 Running 2 7d
kube-system kube-controller-manager 1/1 Running 0 7d
kube-system kube-dns-5c76d6bddb-8zhmq 3/3 Running 1 7d
kube-system kube-proxy-xq8j6 1/1 Running 0 7d
kube-system kube-scheduler- 1/1 Running 0 7d
kube-system tiller-deploy-5b7cb9cfd7-j725s 1/1 Running 0 7d
my-system glusterfs-brick-0 0/2 Pending 0 3m
my-system sticky-scheduler-6d968f8d74-xvjqn 0/1 ImagePullBackOff 0 4m

所以从上面的输出我想打印这些失败的 pod
NAMESPACE       NAME                                        READY     STATUS             RESTARTS   AGE
default pod-with-sidecar 1/2 ErrImagePull 0 4m
my-system glusterfs-brick-0 0/2 Pending 0 56s
my-system sticky-scheduler-6d968f8d74-xvjqn 0/1 ImagePullBackOff 0 8m

这有效!
$ kubectl get pods --all-namespaces | grep -vE '1/1|2/2|3/3'

NAMESPACE NAME READY STATUS RESTARTS AGE
default pod-with-sidecar 1/2 ErrImagePull 0 4m
my-system glusterfs-brick-0 0/2 Pending 0 56s
my-system sticky-scheduler-6d968f8d74-xvjqn 0/1 ImagePullBackOff 0 8m

但是如果我有 2/4,0/4,0/5,0/6 就不行了等在 Ready专栏,我可以用 grep -vE '1/1|2/2|3/3' 做什么使其适用于所有此类情况

引用: https://github.com/kubernetes/kubernetes/issues/49387

最佳答案

使用 GNU grep:

 | grep -Ev '([0-9]+)/\1'

输出:

NAMESPACE NAME READY STATUS RESTARTS 年龄
默认 pod-with-sidecar 1/2 ErrImagePull 0 39s
我的系统 glusterfs-brick-0 0/2 待定 0 3m
我的系统粘性调度程序 6d968f8d74-xvjqn 0/1 ImagePullBackOff 0 4m

关于kubernetes - 从 kubectl 输出显示失败的 pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56673619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com