gpt4 book ai didi

kubernetes - 使用 kubectl 列出给定命名空间中的所有对象

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

我想列出 kubernetes 中特定命名空间中存在的所有对象。

kubectl get all -n <namespace>

上面的命令没有列出给定命名空间中的所有可用对象。有没有办法使用 kubectl 列出它们?

我可以通过将它们传递给 kubectl 来列出我想要的所有对象。但我不想那样。
kubectl -n <namespace> get deployment,rs,sts,ds,job,cronjobs -oyaml

最佳答案

首先,以下规则决定资源是否属于 全部 类别与否。

Here are the rules to add a new resource to the kubectl get all output.


  • 没有集群范围的资源
  • 没有命名空间管理员级别的资源(限制、配额、策略、
    授权规则)
  • 没有可能无法恢复的资源( secret 和 pvc)
  • 被认为与#3“相似”的资源应归为
    相同(配置映射)

  • 回答您的问题 这是取自 rcorre's Answer
    kubectl api-resources --verbs=list --namespaced -o name \
    | xargs -n 1 kubectl get --show-kind --ignore-not-found -l <label>=<value> -n <namespace>

    最后,如果您想在 中添加自定义资源所有类别 ,您需要在 CRD 规范中提供这些字段。 custom-resource-definitions:categories
    # categories is a list of grouped resources the custom resource belongs to.
    categories:
    - all

    关于kubernetes - 使用 kubectl 列出给定命名空间中的所有对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57002814/

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