Created
June 1, 2018 20:55
-
-
Save vidhill/20d4c6ae231aa84e34078ac83e10c5f0 to your computer and use it in GitHub Desktop.
Kubectl: workaround to get a list of pods for a service
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
#!/bin/bash | |
if [ "$1" != "" ]; then | |
echo "Get pods in service: $1" | |
else | |
echo "Service blank" | |
echo "Pass the target service" | |
exit 1 | |
fi | |
SELECTORS=$(kubectl get svc/"$1" -o=go-template='{{ range $key, $value := .spec.selector }}{{$key}}={{$value}},{{ end }}'); | |
SELECTORS=${SELECTORS%?} | |
kubectl get pods --selector="$SELECTORS"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment