Snippets for your daily work with Kubernetes

Snippets for your daily work with Kubernetes
Photo by Evelyn Clement / Unsplash

Display all Pods that are not completely ready

kubectl get pods -A | grep -v "Completed" | grep -v "1/1" | grep -v "2/2" | grep -v "3/3" | grep -v "4/4"
watch 'kubectl get pods -A | grep -v "Completed" | grep -v "1/1" | grep -v "2/2" | grep -v "3/3" | grep -v "4/4"'

Delete all ReplicaSets with no Pods assigned

kubectl get replicaset -A -o=jsonpath='{range .items[?(@.spec.replicas==0)]}{.metadata.name}{"\t"}{.metadata.namespace}{"\n"}{end}' | awk '{print $1 " --namespace=" $2}' | xargs -n 2 -d '\n' bash -c 'kubectl delete replicaset $0 $1'

Count all evicted Pods in Cluster

kubectl get pods -A | grep Evicted | wc -l

Delete all evicted pods from all namespaces

kubectl get pods -A | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs -n 2 -d '\n' bash -c 'kubectl delete pod $0 $1'

Remove Finalizers of all ArgoCD Applications

for application in $(kubectl get applications.argoproj.io -o name);
do
  kubectl get ${application} -o=json | jq '.metadata.finalizers=null' | kubectl apply -f -
done