Reputation: 2534
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>
Upvotes: 14
Views: 10850
Reputation: 1761
Some of the answers provide either lengthy terminal commands or very short description of what the commands actually do.
The shortest possible command to identify a static pod via kubectl
:
kubectl describe pods -A | grep -i Controlled
will list all pods in all namespaces and check for the controlled by field. The Node/***
presence on stdout indicates static pods presence.
Note: this assumes of course that a cluster already exists. If you are bootstrapping your own cluster, or you are curious about how kubeadm
works, you can inspect the kubelet
node - e.g. by ssh
into it - and search the local directory for pod manifests
files (usually at /etc/kubernetes/manifests
and/or /var/lib/kubelet
)
Upvotes: 1
Reputation: 4328
Get all pods in all namespaces, and look for the ones that have an ownerReferences
a node:
kubectl get pods -A -ojson | jq -r '.items | map(select(.metadata.ownerReferences[0].kind == "Node" ) | .metadata.name) | .[]'
Also Static pods have the node name in their name:
Upvotes: 0
Reputation: 31
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
Upvotes: 3
Reputation: 23
You can just run the command below and check the pods with -controlplane appended in their name.
kubectl get pods --all-namespaces
Upvotes: 1
Reputation: 21
You can use that:
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
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"
Upvotes: 2
Reputation: 19342
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
Upvotes: 17
Reputation: 33
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) | .[]'
Upvotes: 1
Reputation: 11346
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
Upvotes: 17