Skip to content

Instantly share code, notes, and snippets.

@flavianmissi
Created March 22, 2017 16:11
Show Gist options
  • Save flavianmissi/1d11cd942b4ff194406891fbd9b7a137 to your computer and use it in GitHub Desktop.
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
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