SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. NS=$1
  3. NS_CHECK=$(kubectl get ns | grep $NS | awk '{print $1}')
  4. if [[ $NS_CHECK == $NS ]];
  5. then
  6. echo "Namespace $NS will be deleted"
  7. else
  8. echo "No such namespace named $NS"
  9. exit 1
  10. fi
  11. kubectl delete ns $NS --force=true --grace-period=0 > /dev/null 2>&1 &
  12. echo "Start kubectl proxy on port 8080"
  13. kubectl proxy --port=8080 &
  14. PROXY_PID=$!
  15. sleep 1
  16. kubectl get namespace $NS -o json > /tmp/ns.json
  17. jq 'del(.spec.finalizers[])' /tmp/ns.json > /tmp/new-ns.json
  18. echo "Delete namespace $NS"
  19. sleep 1
  20. curl -k -H "Content-Type: application/json" -X PUT --data-binary @/tmp/new-ns.json http://127.0.0.1:8080/api/v1/namespaces/$NS/finalize > /dev/null 2>&1
  21. rm -rf /tmp/ns.json /tmp/new-ns.json
  22. echo "Namespace $NS deleted"
  23. echo "Stop kubectl proxy"
  24. kill $PROXY_PID
  25. wait $PROXY_PID 2>/dev/null
  26. sleep 1
  27. echo "Kubectl proxy stoped"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top