Skip to content

Instantly share code, notes, and snippets.

@claudioacioli
Last active June 12, 2021 12:00
Show Gist options
  • Save claudioacioli/05176c31b7aae0165c176a067aa234d7 to your computer and use it in GitHub Desktop.
Save claudioacioli/05176c31b7aae0165c176a067aa234d7 to your computer and use it in GitHub Desktop.
When you are studding k8s and you need to clear your minikube cluster all time.

clearkube

When you are studding k8s and you need to clear your minikube cluster all time.

Install

Download and make it executable:

curl -LO "https://gist.githubusercontent.com/claudioacioli/05176c31b7aae0165c176a067aa234d7/raw/64e6f283c6a22e1d75b3d5f56c09016f02fbb25e/clearkube"
chmod 744 clearkube

Usage

Create a sample deployment and expose it on port 8080: See more on minikube start

kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080

Then clear it with:

./clearkube hello-minikube
#!/bin/sh
if [ -n "$1" ]
then
POD_NAME=$(kubectl get pods -o go-template --template '{{range.items}}{{.metadata.name}}{{"\n"}}{{end}}')
fi;
[ -n "$1" ] && kubectl delete -n default deployment "$1"
[ -n "$POD_NAME" ] && kubectl delete -n default pod "$POD_NAME"
[ -n "$1" ] && kubectl delete -n default service "$1"
[ -z "$1" ] && printf "\nYou need pass a deployment name like:\n\n \$ clearkube my_deployment_name\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment