Goglides Dev 🌱

Goglides Dev 🌱 is a community of amazing users

We are working on this space so that IT professionals can grow together.

Create account Log in
Balkrishna Pandey
Balkrishna Pandey

Posted on

how to get/delete pods based on nodename

  • Get pods in a default namespace using nodename
oc get pods --field-selector spec.nodeName=master-1 -o wide
Enter fullscreen mode Exit fullscreen mode
  • Get pods in all namespaces using nodename
oc get pods --field-selector spec.nodeName=master-1 -A -o wide
Enter fullscreen mode Exit fullscreen mode
  • Delete pods in a default namespace using nodename
oc delete pods --field-selector spec.nodeName=master-1 -o wide
Enter fullscreen mode Exit fullscreen mode
  • Delete pods in all namespaces using nodename
oc delete pods --field-selector spec.nodeName=master-1 -A -o wide
Enter fullscreen mode Exit fullscreen mode
  • Sort pods based on nodename
oc get pods -o wide --sort-by="{.spec.nodeName}"

Enter fullscreen mode Exit fullscreen mode
  • Find all pods deployed in master nodes, sort by nodes, remove field-selector.
for node in $(oc get nodes -l node-role.kubernetes.io/master= --no-headers | cut -d " " -f1); do      oc get pods --all-namespaces  --no-headers --field-selector spec.nodeName=${node} -o wide ; done
Enter fullscreen mode Exit fullscreen mode

Discussion (0)