Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out all the pods that are using default service account

We have a k8s cluster with 10 workers. we run hundreds of pods in the cluster. we want to avoid running pods with default service account. Need to find out the pods that are running with default service account. am able to find the number of pods using default service account with grep command but also need the pod name and the image it is using. Let us know your thoughts

like image 736
P Ekambaram Avatar asked Sep 07 '25 02:09

P Ekambaram


1 Answers

  • In Case if you want to use just kubectl without jq :

needed to print both namespace and the pod name

kubectl get pods --all-namespaces -o jsonpath='{range .items[?(@.spec.serviceAccountName == "default")]}{.metadata.namespace} {.metadata.name}{"\n"}{end}' 2>/dev/null
  • i have added 2>/dev/null to avoid printing whole json template in case if no field was found
like image 75
confused genius Avatar answered Sep 10 '25 15:09

confused genius