Get AWS Instance-ID from all Kubernetes nodes

kubectl get node -ojson | jq -r '.items[].spec.providerID' | cut -d/ -f5 | tr -d '"'

June 29, 2023tanmay-bhat


  • Get all the node spec details via JSON
  • Use jq to iterate over the objects to fetch the providerID which will be in form of originally : aws:///<zone>/i-0123456789
  • Use cut command to split the string with / as delimiter and extract the 5th field.
  • Use tr finally to remove the trailing " (by deleting all occurences of ")