Skip to content
Snippets Groups Projects
Commit b0a69478 authored by František Dvořák's avatar František Dvořák
Browse files

Script for cleaning kubernetes pods stuck in "Terminating" state

parent 807189f6
No related branches found
No related tags found
No related merge requests found
#! /bin/sh
#
# Clean kubernetes pods stuck in "Terminating" state
#
# Example:
#
# k8s-pods-cleaner.sh hub app=jupyterhub,component=singleuser-server --yes
#
if [ -z "$1" ]; then
echo "Usage: $0 NAMESPACE [QUERY [--yes]]"
exit 0
fi
NS="$1"
QUERY="$2"
PERFORM="$3"
for pod in $(kubectl get pod -n "$NS" -l "$QUERY" --field-selector="status.phase==Failed" -ojsonpath='{.items[*].metadata.name}'); do
if [ -n "$PERFORM" ]; then
kubectl get pod -n "$NS" "$pod" -oyaml > "/tmp/$NS-$pod.yaml"
kubectl delete pod -n "$NS" "$pod" --force
else
kubectl get pod -n "$NS" "$pod"
fi
done
...@@ -167,6 +167,11 @@ ...@@ -167,6 +167,11 @@
dest: /etc/profile.d/k8s-cheats.sh dest: /etc/profile.d/k8s-cheats.sh
src: files//etc/profile.d/k8s-cheats.sh src: files//etc/profile.d/k8s-cheats.sh
mode: preserve mode: preserve
- name: K8s pods cleaner
copy:
dest: /usr/local/bin/k8s-pods-cleaner.sh
src: files/usr/local/bin/k8s-pods-cleaner.sh
mode: preserve
- name: K8s network deployment - name: K8s network deployment
hosts: master hosts: master
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment