Skip to content

Instantly share code, notes, and snippets.

@ghelobytes
Last active October 12, 2023 22:00
Show Gist options
  • Save ghelobytes/cf1648d5cc2f4411d2f294c37648f515 to your computer and use it in GitHub Desktop.
Save ghelobytes/cf1648d5cc2f4411d2f294c37648f515 to your computer and use it in GitHub Desktop.
k8 scripts
# Show disk space info for all pod
n=mynamespace bash -c 'for pod in $(kubectl get pods -n $n -o=jsonpath="{.items[*].metadata.name}"); do echo $pod; kubectl exec -it $pod -n $n -- df -h; echo "\n"; done'
# usage: delete_evicted_pods.sh my-namespace
kubectl get pod -n $1 | grep Evicted | awk '{print $1}' | xargs kubectl delete pod -n $1
# usage: get_logs.sh my-namespace
for pod in $(kubectl get pods -n $1 -o=jsonpath='{.items[*].metadata.name}'); do echo "Logs for Pod: $pod"; kubectl logs $pod -n $1; echo "------------------------------------------------------------"; done
# usage: get_messages.sh my-namespace
for pod in $(kubectl get pods -n $1 -o=jsonpath='{.items[*].metadata.name}'); do echo "Messages for Pod: $pod"; kubectl describe $pod -n $1 | grep Message; echo "------------------------------------------------------------"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment