12

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>
Eduardo Baitello
  • 10,469
  • 7
  • 46
  • 74
Mamun
  • 2,322
  • 4
  • 27
  • 41

6 Answers6

16

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

pkaramol
  • 16,451
  • 43
  • 149
  • 324
  • 9
    Also: static pods always have a -${NODENAME} appended to their name, indicating which node controls this static pod. – meaningqo Jan 11 '21 at 08:05
11

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
Eduardo Baitello
  • 10,469
  • 7
  • 46
  • 74
  • 1
    FYI - To add a column for the node name and grep for Node: `kubectl get pods -A -o custom-columns=NAME:.metadata.name,CONTROLLER:.metadata.ownerReferences[].kind,NAMESPACE:.metadata.namespace,NODE:.spec.nodeName | grep Node` – AndrewRalon Mar 25 '22 at 21:10
2

You can use that:

  • For count static pod:
kubectl get pods -A --no-headers | awk '{print $2 " -n " $1 "\n"}' | xargs --max-lines=1 kubectl describe pods | grep "Controlled By:  Node/controlplane" | wc -l
  • For list what is static pod:
kubectl get pods -A --no-headers | awk '{print $2 " -n " $1 "\n"}' | xargs --verbose --max-lines=1 kubectl describe pods | grep "Controlled By:  Node/controlplane"
1

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) | .[]'
Scott
  • 33
  • 5
0

You can just run the command below and check the pods with -controlplane appended in their name.

kubectl get pods --all-namespaces
Stinger
  • 13
  • 5
0
ontrolplane ~ ➜  kubectl get pods --all-namespaces
NAMESPACE      NAME                                   READY   STATUS    RESTARTS   AGE
kube-flannel   kube-flannel-ds-mmm9q                  1/1     Running   0          41m
kube-flannel   kube-flannel-ds-ptks8                  1/1     Running   0          41m
kube-system    coredns-5d78c9869d-p6tv6               1/1     Running   0          41m
kube-system    coredns-5d78c9869d-q4s44               1/1     Running   0          41m
kube-system    etcd-controlplane                      1/1     Running   0          41m
kube-system    kube-apiserver-controlplane            1/1     Running   0          41m
kube-system    kube-controller-manager-controlplane   1/1     Running   0          41m
kube-system    kube-proxy-n8crp                       1/1     Running   0          41m
kube-system    kube-proxy-s96g7                       1/1     Running   0          41m
kube-system    kube-scheduler-controlplane            1/1     Running   0          41m

You just have to look for pods name which end with particular node name. Means owner of POD is node (control plane) in place of standard POD names. Are static pod

toyota Supra
  • 3,181
  • 4
  • 15
  • 19