Jé pa l'temps #22 - Force to delete a terminating ns in Kubernetes

Thought API methods

Firstly you hate to request the API to get namespace’s data and dave them.

# Describe namespace data and save it to a JSON
kubectl get namespace longhorn-system -o json > tmp.json

After that, editing this JSON to remove finalizers: it should became an empty array.

Once it is done, you want to apply the changes to your cluster. For doing that, you can proxy your cluster’s API to the local.

# Proxy cluster's API
kubectl proxy & 
# Save the PID of the process
PID=$! 
# Apply the edited file to the cluster
curl -X PUT http://localhost:8001/api/v1/namespaces/longhorn-system/finalize -H "Content-Type: application/json" --data-binary @tmp.json
# Kill the process just created
kill $PID

It should work.

Script trying

# List namespace
#Array=(
#  'harbor'
#)

#for NAMESPACE in "${Array[@]}"; do
#  echo $NAMESPACE
#  kubectl get namespace $NAMESPACE -o json > delete-namespace.json

# node -e "const file = require('./delete-namespace.json');const fs = require('fs');file.items[0].spec.finalizers = [];fs.writeFileSync('./delete-namespace.json', JSON.stringify(file));"

#  # kubectl proxy &
#  # PID=$!
#  # curl -X PUT http://localhost:8001/api/v1/namespaces/$NAMESPACE/finalize -H "Content-Type: application/json" --data-binary @delete-namespace.json
#  # kill $PID
#done

— — — — — — — — — — — — — — — — — — — — —

La série « Jé pa l’temps » est une série de tutoriels rapides en mode “prise de note” pour avoir une trace de tout ce dont je ne peux me rappeler et pourquoi pas le partager à d’autre. On va à l’essentiel, laissons les jolis pavés à d’autres sites comme medium… LOL !