Skip to content

Instantly share code, notes, and snippets.

@rms1000watt
Last active November 29, 2018 09:28
Show Gist options
  • Save rms1000watt/999a25e2b57d9bc0c5b9ebc06c890174 to your computer and use it in GitHub Desktop.
Save rms1000watt/999a25e2b57d9bc0c5b9ebc06c890174 to your computer and use it in GitHub Desktop.
Nuke kubernetes service in a namespace

Kubenukem

Introduction

Nuke everything in a namespace following a grep pattern

Contents

Install

brew tap rms1000watt/rms1000watt
brew install kubenukem

Usage

kubenukem tiller
kubenukem kube-system tiller
#!/usr/bin/env bash
# kubenukem tiller
# kubenukem kube-system tiller
if [[ -z $1 ]]; then
echo "ERROR: no service provided in default namespace"
exit 1
fi
namespace=$1
service=$2
if [[ -z $service ]]; then
service=$1
namespace=default
fi
things=(deployment replicaset statefulset daemonset service job hpa pod role rolebinding clusterrole clusterrolebinding serviceaccount)
for thing in "${things[@]}"; do
for thingy in "$(kubectl -n "$namespace" get "$thing" | grep "$service")"; do
for t in $(echo "$thingy"| cut -d' ' -f1); do
kubectl -n "$namespace" delete "$thing" "$t" --now --force --cascade=false
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment