I have several pods in 2 nodes in my Kubernetes cluster. (Please see below).
Is there a way I can tell which ones are static pods? (maybe a kubectl command of sort?)
Thanks!
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>
Checking the owner reference of a static pod using kubectl describe command should indicate that such a pod is not controlled by a ReplicaSet but rather from Node/controlplane
You can filter by the OwnerReference.Kind. Static pods have the Node ownerReference kind.
You can use --custom-columns to list all your pods and its owner references. Example:
$ 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
Or use jq to filter only the Static pods (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
On Kubernetes v1.16.3 metadata.ownerReferences.kind isn't a thing so the recommended answer here didn't work. I was able to identify Static Pods by looking at the metadata.labels.tier key/value pair with equal to "control-plane" with jq using the following.
kubectl get pods --all-namespaces -o json | jq -r '.items | map(select(.metadata.labels.tier == "control-plane" ) | .metadata.name) | .[]'