Skip to content

Tips and Tricks - Helping Tools

kubectl trics and conventions

Change default editor (Vim) to nano

Edit

nano ~/.bashrc
Add a line (on the bottom of the file)
export KUBE_EDITOR="nano"

source ~/.bashrc

If you need to see join command again

kubeadm token create --print-join-command

Enable kubectl autocomplete (bash)

echo 'source <(kubectl completion bash)' >>~/.bashrc

Enable kubectl autocomplete (zsh)

echo "source <(kubectl completion zsh)" >> ~/.zshrc

Prune Containerd Unused Images (Run on nodes)

crictl rmi --prune

Delete evicted pods

kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod

Namespace stuck in terminating state

kubectl get namespace "<NAMESPACE>" -o json \
  | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
  | kubectl replace --raw /api/v1/namespaces/<NAMESPACE>/finalize -f -