Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dlinsley/5e4b7bc47fd18d3046c8cf18d16a6511 to your computer and use it in GitHub Desktop.
Save dlinsley/5e4b7bc47fd18d3046c8cf18d16a6511 to your computer and use it in GitHub Desktop.
Delete certain Kubernetes objects across all namespaces with parallel

Samples to cleanup multiple configs across multiple namespaces in Kubernetes using kubectl and GNU parallel

#/bin/bash
kubectl get replicaset -A | awk '$3==0 && $4==0 && $5==0 {print $1,$2}' | parallel --jobs 4 --colsep ' ' kubectl delete replicaset -n {1} {2}
#!/bin/bash
kubectl get pods -A | grep 'Evicted' | awk '{print $1,$2}' | parallel --jobs 4 --colsep ' ' kubectl delete pod -n {1} {2}
#/bin/bash
kubectl get secrets -A | grep 'istio.io/key-and-cert' | awk '{print $1,$2}' | parallel --jobs 4 --colsep ' ' kubectl delete secret -n {1} {2}
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: getdeployresourcerequests <namespace>"
exit 1
fi
kubectl get deploy -n $1 -o custom-columns=NAME:.metadata.name,CPU_Requests:.spec.template.spec.containers[].resources.requests.cpu,MEM_Requests:.spec.template.spec.containers[].resources.requests.memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment