I am creating a bash script to automate certain actions in my cluster. One of the commands is: kubectl delete -f example.yaml.
The problem is that when the resources defined in the YAML do not exist, the following error is printed:
Error from server (NotFound): error when deleting "example.yaml": deployments.apps "my_app" not found
I am looking to add an additional step that first checks whether a set of resources defined in a YAML file exist in the cluster. Is there a command that would allow me to do so?
From the documentation, I found:
Compares the current state of the cluster against the state that the cluster would be in if the manifest was applied.
kubectl diff -f ./my-manifest.yaml
but I find it difficult to parse the output that it returns. Is there a better alternative?