gpt4 book ai didi

kubernetes - Kubectl获取pod的状态为Yaml

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

我可以运行kubectl get pod nginx -o=jsonpath={'.status'}来获取我的Pod的json中的状态。

如何进行相同的过滤,但结果以yaml而不是json的形式返回?

所以我想通过命令获得这种输出:

status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2019-05-31T14:58:57Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2019-05-31T14:59:02Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2019-05-31T14:58:57Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://5eb07d9c8c4de3b1ba454616ef7b258d9ce5548a46d4d5521a0ec5bc2d36b716
image: nginx:1.15.12
imageID: docker-pullable://nginx@sha256:1d0dfe527f801c596818da756e01fa0e7af4649b15edc3eb245e8da92c8381f8
lastState: {}
name: nginx
ready: true
restartCount: 0
state:
running:
startedAt: "2019-05-31T14:59:01Z"

最佳答案

您无法使用kubectl做到这一点,它没有此类输出选项。

但是,使用awk提取这些行应该很容易。

kubectl get pods -o yaml | awk '/^status:/{flag=1}flag'

这将在 status:行开始输出。在这种情况下,这正是您想要的。

关于kubernetes - Kubectl获取pod的状态为Yaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56396717/

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