Skip to content

Instantly share code, notes, and snippets.

@leadelngalame1611
Last active February 8, 2023 12:35
Show Gist options
  • Save leadelngalame1611/63f65c228684160472122945cd6746b8 to your computer and use it in GitHub Desktop.
Save leadelngalame1611/63f65c228684160472122945cd6746b8 to your computer and use it in GitHub Desktop.
kubectl_commands
## Delete a namespace that get stuck
> NS=`kubectl get ns |grep Terminating | awk 'NR==1 {print $1}'` && kubectl get namespace "$NS" -o json | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" | kubectl replace --raw /api/v1/namespaces/$NS/finalize -f -
## Delete a Pod that get stock
# Create the namespace if not exist
> kubectl create namespace <namespace_name>
> kubectl patch pod k8s-runners-nonlive-gfdt2-lgnt8 -p '{"metadata": {"finalizers":null}}'
# Get all kind runners and remove the finalizer
> kubectl get runners --no-headers | awk {'print $1'} | xargs kubectl patch runner --type merge -p '{"metadata":{"finalizers":null}}'
# Get all pods that are stuck terminating and remove the finalizer
> kubectl -n get pods | grep Terminating | awk {'print $1'} | xargs kubectl patch pod -p '{"metadata":{"finalizers":null}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment