kubernetes 如何通过kubectl命令识别静态pod?

iaqfqrcu  于 2023-01-12  发布在  Kubernetes
关注(0)|答案(3)|浏览(180)

我在Kubernetes集群的2个节点中有几个Pod。(请参见下文)。
有没有办法分辨哪些是静态pod?(也许是kubectl命令之类的?)
谢谢!

controlplane $ k get pods -A -o wide
NAMESPACE     NAME                                   READY   STATUS    RESTARTS   AGE    IP            NODE           NOMINATED NODE   READINESS GATES
kube-system   coredns-f9fd979d6-h865q                1/1     Running   0          119s   10.244.0.5    node02   <none>           <none>
kube-system   coredns-f9fd979d6-z4j6f                1/1     Running   0          119s   10.244.1.5    node01         <none>           <none>
kube-system   etcd-a1b2k7h7                      1/1     Running   0          2m9s   172.17.0.79   node02   <none>           <none>
kube-system   kube-apiserver-g8j4k8o8            1/1     Running   0          2m9s   172.17.0.79   node02   <none>           <none>
yr9zkbsy

yr9zkbsy1#

使用kubectl describe命令检查静态pod的所有者引用应指示此类podReplicaSet控制,而是由Node/controlplane控制

vptzau2j

vptzau2j2#

您可以按OwnerReference.Kind进行筛选。静态pod具有**Node**ownerReference类型。
您可以使用--custom-columns列出所有pod及其所有者引用。

$ kubectl get pods --all-namespaces -o custom-columns=NAME:.metadata.name,CONTROLLER:.metadata.ownerReferences[].kind,NAMESPACE:.metadata.namespace
NAME                                        CONTROLLER   NAMESPACE
busybox-6ff78776d5-k56fx                    ReplicaSet   default
nginx-6b87f7d77c-rq6fl                      ReplicaSet   default
coredns-74ff55c5b-xpgnq                     ReplicaSet   kube-system
etcd-minikube                               Node         kube-system
ingress-nginx-admission-create-n6j7k        Job          kube-system
ingress-nginx-admission-patch-45xvw         Job          kube-system
ingress-nginx-controller-65cf89dc4f-g7lwm   ReplicaSet   kube-system
kindnet-44pq8                               DaemonSet    kube-system
kindnet-nqhg9                               DaemonSet    kube-system
kube-apiserver-minikube                     Node         kube-system
kube-controller-manager-minikube            Node         kube-system
kube-proxy-nmzbn                            DaemonSet    kube-system
kube-proxy-wlmdz                            DaemonSet    kube-system
kube-scheduler-minikube                     Node         kube-system
metrics-server-58966dd6b9-schjr             ReplicaSet   kube-system
storage-provisioner                         <none>       kube-system

或使用jq仅过滤静态pod(kind == "Node"):

$ kubectl get pods --all-namespaces -o json | jq -r '.items | map(select(.metadata.ownerReferences[]?.kind == "Node" ) | .metadata.name) | .[]'
etcd-minikube
kube-apiserver-minikube
kube-controller-manager-minikube
kube-scheduler-minikube
c0vxltue

c0vxltue3#

在Kubernetes v1.16.3中,metadata.ownerReferences.kind不是一个东西,因此这里推荐的答案不起作用。我能够通过查看metadata.labels.tier键/值对(等于jq的“控制平面”)来识别静态Pod。

kubectl get pods --all-namespaces -o json | jq -r '.items | map(select(.metadata.labels.tier == "control-plane" ) | .metadata.name) | .[]'

相关问题