dirtyw0lf
dirtyw0lf

Reputation: 1958

deleting all k8s objects by environment

what is the command to remove all objects using kubectl for a specific environment?

kubectl -n squad-mb get all

returns all environments for example, and in order to delete one environment I would like to know how to see it, and which command would be required to delete the specific environment (i.e. develop)

Upvotes: 3

Views: 3937

Answers (3)

dirtyw0lf
dirtyw0lf

Reputation: 1958

kubectl -n namespace delete all pods -l env=dev

Upvotes: 0

victortv
victortv

Reputation: 8892

To delete all resources of a given namespaces use:

kubectl delete all --all -n {my-namespace}

Explanation:

  • Usage: kubectl delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)]) [options]
  • all: all resources types. If you want to delete only some resources you can do kubectl delete deployments,pods,replicasets,services --all
  • --all: delete all resources of a type (or all types if using all). Example: kubectl delete pods --all
  • -n: selects the desired namespace. If empty the command is valid for the default namespace of your context. You can select all namespaces with --all-namespaces

Upvotes: 10

Max Lobur
Max Lobur

Reputation: 6040

Just re-create the namespace:

kubectl delete ns squad-mb
kubectl create ns squad-mb

This will recursively delete everything inside.

Upvotes: 0

Related Questions