kubernetesorder-of-executionteardown

Correct teardown sequence for Kubernetes infrastructure components


In order to deploy my k8s cluster I kubectl apply -f folder-of-yamls/

And it seems that the order of execution is important. One approach I've seen is to prefix 001-namespace.yaml 002-secrets.yaml etc. to create an ordering.

To tear down, if I kubectl delete -f folder-of-yamls/, can I simply reverse the order or must I manually create a sequence?


Solution

  • Order of deletion shouldn't matter to much, as mentioned by David Maze in comments, kubectl delete -f folder/ will clean up everything correctly, however there might be some issues when you delete objects that are dependent from other. For example PVC should be deleted before PV (PV will take forever to be deleted) but kubernetes should take care of that if everything is present in directory you are deleting yamls from.