问题描述
好的,标题很充实.但这实际上是在描述情况.
我在名称空间argo-events中的GKE上部署了服务.它出了点问题,所以我将其拆了:
kubectl删除名称空间argo-events
实际上,问题已经开始(我怀疑与下面描述的问题有关),我不得不求助于
argo-events未由 kubectl get命名空间
列出.只是确认一下.
如果我专门查找它们,我可以找到这两个对象:
$ kubectl get eventbus -n argo-events姓名年龄默认17小时$ kubectl获取事件源-n argo-events姓名年龄pubsub-event-source 14h
但是-我无法通过询问所有对象找到任何东西:
$ kubectl获得所有-n argo-events在argo-events命名空间中找不到资源.
所以我的问题是.如何在Argo事件中通用列出所有挥之不去的对象?
我问,因为否则我将不得不检查整个对象浏览器树以找到更多对象(因为我无法再选择名称空间).
使用命令 $ kubectl get all
,您将只打印一些资源,例如:
- pod
- 服务
- daemonset
- 部署
- 复制包
- statefulset
- 工作
- cronjobs
当您使用 $ kubectl api-resources
时,它不会打印所有可以找到的资源.
示例
从 PersistentVolume 文档中,它不会在 $ kubectl get all
输出中列出,但是如果您指定此资源,它将被列出.
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/storage/pv-volume.yaml创建了persistentvolume/task-pv-volume$ kubectl获取光伏名称能力访问模式声明策略状态声明存储类原因年龄task-pv-volume 10Gi RWO Retain可用手册3m12s$ kubectl全部获得名称类型集群IP外部IP端口的年龄服务/kubernetes ClusterIP 10.3.240.1< none>443/TCP 86分钟$
如果要列出特定 namespace
中的所有资源,则应使用以下命令:
kubectl -n argo-events api-resources --namespaced = true -o名称|xargs --verbose -I {} kubectl -n argo-events get {} --show-kind --ignore-not-found
上述解决方案是在Github线程中提出的. kubectl get all不列出命名空间中的所有资源.在该线程中,您可能会发现上述命令的一些其他变体.
此外,您还可以检查如何在Kubernetes命名空间中列出所有资源.您可以找到使用 function
函数列出资源的方法.
Okay, the title is quite mouthful. But it's actually describing the situation.
I deployed a service on GKE in namespace argo-events. Something was wrong with it so I tore it down:
kubectl delete namespace argo-events
Actually, that's already where the problems started (I suspect a connection to the problem described below) and I had to resort to a hack because argo-events got stuck in a Terminating state forever. But the result was as desired - namespace seemed to be gone together with all objects in it.
Because of problems with redeployment I inspected the GKE Object Browser (just looking around - cannot filter for argo-events namespace anymore as it is officially gone) where I stumbled upon two lingering objects in ns argo-events:
argo-events is not listed by kubectl get namespaces
. Just confirming that.
And I can find those two objects if I look them up specifically:
$ kubectl get eventbus -n argo-events
NAME AGE
default 17h
$ kubectl get eventsource -n argo-events
NAME AGE
pubsub-event-source 14h
But - I cannot find anything by asking for all objects:
$ kubectl get all -n argo-events
No resources found in argo-events namespace.
So my question is. How can I generically list all lingering objects in argo-events?
I'm asking because otherwise I'd have to inspect the entire Object Browser Tree to maybe find more objects (as I cannot select the namespace anymore).
By using command $ kubectl get all
you will only print a few resources like:
- pod
- service
- daemonset
- deployment
- replicaset
- statefulset
- job
- cronjobs
It won't print all resources which can be found when you will use $ kubectl api-resources
.
Example
When create PV
from PersistentVolume docsumentation it won't be listed in $ kubectl get all
output, but it will be listed if you will specify this resource.
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/storage/pv-volume.yaml
persistentvolume/task-pv-volume created
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
task-pv-volume 10Gi RWO Retain Available manual 3m12s
$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.3.240.1 <none> 443/TCP 86m
$
If you would like to list all resources from specific namespace
you should use command below:
kubectl -n argo-events api-resources --namespaced=true -o name | xargs --verbose -I {} kubectl -n argo-events get {} --show-kind --ignore-not-found
Above solution was presented in Github thread kubectl get all does not list all resources in a namespace. In this thread you might find some additional variations of above command.
In addition, you can also check How to List all Resources in a Kubernetes Namespace article. You can find there method to list resources using function
.
这篇关于如何列出不存在的名称空间的所有对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!