Skip to content

Instantly share code, notes, and snippets.

@VMuliadi
Last active August 4, 2021 17:03
Show Gist options
  • Save VMuliadi/5a00817621f175a4361635ab595d97aa to your computer and use it in GitHub Desktop.
Save VMuliadi/5a00817621f175a4361635ab595d97aa to your computer and use it in GitHub Desktop.
# bulk delete pod inside a kubernetes nodes
IFS=$'\n'
for i in $(kubectl describe nodes {{ nodes_name }} | grep -E -- '-fe|-be'); do
ns=$(echo $i | awk '{print $1}')
pod=$(echo $i | awk '{print $2}')
kubectl delete pod -n ${ns} ${pod}
done
# get all pod ips in the cluster and sorted it by ip
# 1st get all pod printed in wide output
# 2nd sort the data from the 7th column
# 3rd parse the data with '.' delimiter and sorted by the 1st 2nd 3rd 4nd data
# 4th print only pod namespace, pod name, and the pod ip
# 5th format the output in a table
kubectl get pod -o wide -A --no-headers | \
sort -t . -k7 -k1,1n -k 2,2n -k 3,3n -k 4,4n | \
tr -s ' ' | cut -d' ' -f1,2,7 | \
column -t -s ' '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment