Skip to content

Instantly share code, notes, and snippets.

@vidhill
Created June 1, 2018 20:55
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 vidhill/20d4c6ae231aa84e34078ac83e10c5f0 to your computer and use it in GitHub Desktop.
Save vidhill/20d4c6ae231aa84e34078ac83e10c5f0 to your computer and use it in GitHub Desktop.
Kubectl: workaround to get a list of pods for a service
#!/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