Created
July 6, 2020 03:54
-
-
Save yokawasa/85296f905ebd7c59b569ee1405a1652a to your computer and use it in GitHub Desktop.
kubectl util script - Show specific label info with node info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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