Created
March 22, 2017 16:11
-
-
Save flavianmissi/1d11cd942b4ff194406891fbd9b7a137 to your computer and use it in GitHub Desktop.
Remove kubernetes services that do not have any deployment with the same name
This file contains hidden or 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
for svc in $(kubectl get svc -o jsonpath='{.items[*].metadata.name}') | |
do | |
kubectl get deploy $svc -o jsonpath='{.items[*].metadata.name}' | |
failed_to_find=$? | |
if [ "$failed_to_find" -eq "1" ] | |
then | |
echo "Could not find deploy for service " $svc ", deleting the service..." | |
kubectl delete svc $svc | |
else | |
echo "Found deploy for svc " $svc # ", look!" | |
#kubectl get deploy $svc | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment