英文:
k8s get all pods hierarchy in cluster with ownerRef's
问题
我们想要获取集群中的所有Pod,所以我们使用类似以下的代码:
pods, err := client.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{})
这段代码将获取集群中的所有Pod。
我的问题是:是否有一段代码或库可以获取所有具有"owner reference"的Pod。
例如,如果Pod由"deployment"或"statefulset"等拥有,您将获取整个层次结构。这里的"技巧"是,如果我需要获取额外的上一级,例如由自定义类型控制器拥有的"statefulset"。
英文:
We want to get all the pods in the cluster so we are using something like following:
pods, err := client.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{})
This code will receive all the pods in the cluster.
My question is: If there is a code or lib which will bring all the pods with the owner reference
.
i.e. if pods owns by deployment
or statfulset
etc you will get all the hierarchy ,the trick
here is if I need to get additional level up like some recursion, for example statefulset
which owns by controller which have custom kind
答案1
得分: 1
根据@CoolNetworking的建议,有一个单一的库或代码可以获取所有带有所有者引用的Pod,但是你可以使用Kubernetes API来检索每个Pod的所有者引用。然后,你可以使用Kubernetes API来检索每个所有者引用的所有者对象。这将允许你创建集群中所有Pod的层次结构。
Kubernetes API是通过HTTP提供的基于资源的(RESTful)编程接口。它支持使用标准的HTTP动词(POST、PUT、PATCH、DELETE、GET)检索、创建、更新和删除主要资源。
大多数Kubernetes API资源类型都是对象:它们表示集群上概念的具体实例,如Pod或命名空间。
请参考kubernetes API文档获取更多信息。
英文:
As @CoolNetworking suggested,there is a single lib or code that will get you all the pods with their owner reference, but you can use k8s API to retrieve the owner references for each pod. You can then use the k8s API to retrieve the owner object for each owner reference. This will allow you to create a hierarchical structure of all the pods in the cluster.
The Kubernetes API is a resource-based (RESTful) programmatic interface provided via HTTP. It supports retrieving, creating, updating, and deleting primary resources via the standard HTTP verbs (POST, PUT, PATCH, DELETE, GET).
Most Kubernetes API resource types are objects: they represent a concrete instance of a concept on the cluster, like a pod or namespace.
Refer the document on kubernetes API for more information
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论