What is the proper way of removing a deployment from kubernetes cleanly

1/13/2019

I have an example deployment running on a kubernetes cluster that also exposes a service and has a persistent volume bound by persistent volume claim.

I would expect that running:

kubectl delete deployment 'deployment_name'

Will delete everything but after running the above the service and storage still exist and I still have to manually delete the service and the persistent volume for the persistent volume claim to release.

Isn't there a single command to remove everything cleanly?

Thank you.

-- user2324712
kubernetes

2 Answers

1/13/2019

If you are creating deployment, service and PV in 3 separate YAML files you will have to remove them one by one.

However if you have 3 of them in the same YAML file, you can delete all three at once by applying:

kubectl delete -f file.yaml
-- Ivan
Source: StackOverflow

1/13/2019

If you have defined deployment, pv, pvc and service in a single file say file.yaml, then you can delete all of them using single command:

kubectl delete -f file.yaml

This will delete all the objects defined in that yaml file.

-- Prafull Ladha
Source: StackOverflow