Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to specify that a resource should not exist #867

Closed
justinkillen opened this issue May 10, 2020 · 4 comments
Closed

Be able to specify that a resource should not exist #867

justinkillen opened this issue May 10, 2020 · 4 comments

Comments

@justinkillen
Copy link

justinkillen commented May 10, 2020

We run all yaml changes through a git repo which is then later applied via CI/CD running:kubectl apply -k .

Unfortunately, when a yaml file is removed, kubectl will not delete the resource and it becomes orphaned, and the yaml is no longer declarative. Contrast this with tools like Terraform and AWS Cloudformation - both of those will remove resource that are no longer declared.

The approach of kubectl seems more inline with e.g. puppet file handling, where you have managed files (some puppet code exists) and unmanaged files (no puppet code exists). When converting from managed to unmanaged, the file still exists on the system, it is just no longer manipulated by puppet. But puppet also has a mechanism for explicitly stating that a file should not exist.

I propose that kubectl have a similar mechanism for identifying resources that SHOULD NOT exist. Proposed syntax:

---
apiVersion: v1
kind: Pod
metadata:
  name: my-app
lifecyle: destroy
@badjware
Copy link

Have you tried the using --prune command-line argument? It allows automatic deletion of resources that are not declared in the provided yaml.

@justinkillen
Copy link
Author

The prune option is nice, but it makes a lot of assumptions and requires a lot of overhead in setting it up correctly. In particular, it moves filtering from the resource-specific yamls into the general-purpose command line. It causes the kubectl command line to be highly coupled to the yamls, which seems like a bad idea.

@justinkillen
Copy link
Author

Or I guess perhaps in the kustomization.yaml you just add one label, and that is used on the prune. Hmm.

@justinkillen
Copy link
Author

Seems there is already work going into making this better. Closing this issue as a duplicate of kubernetes/enhancements#810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants