Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Created July 6, 2020 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokawasa/85296f905ebd7c59b569ee1405a1652a to your computer and use it in GitHub Desktop.
Save yokawasa/85296f905ebd7c59b569ee1405a1652a to your computer and use it in GitHub Desktop.
kubectl util script - Show specific label info with node info
#!/usr/bin/env bash
LABEL=$1
IFS=$'\n'
for l in $(kubectl get node --show-labels |awk '{print $1 " " $2 " " $6}' | tail -n +2)
do
n=$(echo $l | awk '{print $1}')
s=$(echo $l | awk '{print $2}')
ng=$(echo $l | awk '{print $3}' | awk -v label=${LABEL} '
BEGIN{ FS = "," }
{
for(i = 1; i <= NF; i++){
split($i, a, "=")
if(a[1]== label){
print(a[2])
}
}
}
')
echo "${n} ${s} ${ng}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment