2

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?

P i
  • 29,020
  • 36
  • 159
  • 267
  • 1
    fyi the [order helm installs](https://github.com/helm/helm/blob/release-3.4/pkg/releaseutil/kind_sorter.go#L31) and [uninstalls](https://github.com/helm/helm/blob/release-3.4/pkg/releaseutil/kind_sorter.go#L71) – Matt Nov 20 '20 at 11:36
  • 1
    IME the order of execution isn't that important, but there's also an assumption that it's okay if a pod crashes and restarts if something it calls out to isn't available. If there are object-level dependencies (a Pod gets a value from a ConfigMap) `kubectl delete -f folder/` should clean everything up correctly. – David Maze Nov 20 '20 at 12:21

1 Answers1

1

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.

kool
  • 3,214
  • 1
  • 10
  • 26