Skip to content

Instantly share code, notes, and snippets.

@caruccio
Last active October 14, 2020 20:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caruccio/ee0d352e88d164a2550e5d4f7550bdd5 to your computer and use it in GitHub Desktop.
Save caruccio/ee0d352e88d164a2550e5d4f7550bdd5 to your computer and use it in GitHub Desktop.
How to identify and remove resources stuck in Terminating state

Namespaces

List all resources within a namespace

NS=some-namespace

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $NS

Force-delete namespace with stuck finalizer (unsafe)

kubectl proxy &
kubectl get ns $NS -o json \
  | jq '.spec.finalizers=[]' \
  | curl -X PUT http://localhost:8001/api/v1/namespaces/$NS/finalize -H "Content-Type: application/json" --data @-

Pods

Failure to umount secret/configmap

# POD_UID=2dc52da6-50c7-4c39-af65-d99d548761d1
# mount |grep $POD_UID
tmpfs on /var/lib/kubelet/pods/2dc52da6-50c7-4c39-af65-d99d548761d1/volumes/kubernetes.io~secret/mypod-api-token-7qmcf type tmpfs (rw,relatime,seclabel)
# umount /var/lib/kubelet/pods/2dc52da6-50c7-4c39-af65-d99d548761d1/volumes/kubernetes.io~secret/mypod-api-token-7qmcf

Running kubectl log ... returns No space left on device even if all devices are <100% usage

## look for inotify watches and instances limits:

# sysctl -a 2>/dev/null | grep inotify
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 128
fs.inotify.max_user_watches = 8192
user.max_inotify_instances = 128
user.max_inotify_watches = 8192

DotNet apps are huge consumers of inotify watches:

# sysctl -w fs.inotify.max_queued_events=1024 \
            fs.inotify.max_user_instances=524288 \
            fs.inotify.max_user_watches=524288 \
            user.max_inotify_instances=524288 \
            user.max_inotify_watches=524288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment