deleting all k8s objects by environment

4/24/2019

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)

-- dirtyw0lf
kubectl
kubernetes

3 Answers

4/24/2019

Just re-create the namespace:

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

This will recursively delete everything inside.

-- Max Lobur
Source: StackOverflow

5/11/2019

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

-- dirtyw0lf
Source: StackOverflow

4/24/2019

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
-- victortv
Source: StackOverflow