Skip to content

Instantly share code, notes, and snippets.

@spensireli
Created September 20, 2022 17:13
Show Gist options
  • Save spensireli/4f77917bf2874d9447c3b11ad18d42a0 to your computer and use it in GitHub Desktop.
Save spensireli/4f77917bf2874d9447c3b11ad18d42a0 to your computer and use it in GitHub Desktop.
Handy Kubernetes Gists

Cordon all nodes.

for i in $(kubectl get nodes | grep ip |awk '{print $1}'); do kubectl cordon $i; done

Deletes a namespace stuck in terminating.

kubectl get namespace <terminating-namespace> -o json >tmp.json

Edit the json file and remove “kubernetes” from the finalizer. So your spec will look something like this.

      "spec": {
         "finalizers": []
      },

Connect to the kube api.

kubectl proxy

Update the finalizers using the API.

 curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize

Deletes pods that are stuck in a terminating state.

kubectl delete pod --grace-period=0 --force --namespace <NAMESPACE> <PODNAME>

Creates a temporary container to troubleshoot networking within Kubernetes.

kubectl -n amazon-cloudwatch  run tmp-shell --restart=Never --rm -i --tty --image nicolaka/netshoot -- /bin/bash

Uncordon all nodes.

for i in $(kubectl get nodes | grep ip |awk '{print $1}'); do kubectl uncordon $i; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment