k8s 相关

发布时间 2023-08-23 14:21:08作者: bhxuwei

转载至:https://blog.51cto.com/u_15287666/5805969

查询所有命名空间下image运行起来的资源

kubectl get all -o wide -A

缺点:这种方法 kubectl get all 其实查询出来不是全部资源,仅仅是常用资源,仅仅是 service - deployment/statefulset/daemonset/job/cronjob - replicaset - pod 这个绑定链资源,还有 rbac 的 role rolebinding,配置文件 configmap secrets,服务账号 serviceAccount ,service与pod的绑定endpoints都没有查询出来,且看下文。

查询k8s集群所有资源的kind种类

kubectl api-resources --verbs=list --namespaced -o name

解释:-o 表示输出 -o name 表示仅仅输出名称 (类似mysql语句中select的功能)

查询所有命名空间下的所有资源

kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -A

也可以只查询一个命名空间下的所有资源

kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n xxx(ns-name)