<p>i'm working on a continuous deployment routine for a kubernetes application: everytime i push a git tag, a github action is activated which calls <code>kubectl apply -f kubernetes</code> to apply a bunch of yaml kubernetes definitions</p>

<p>let's say i add yaml for a new service, and deploy it -- kubectl will add it</p>

<p>but then later on, i simply delete the yaml for that service, and redeploy -- kubectl will NOT delete it</p>

<p>is there any way that <code>kubectl</code> can recognize that the service yaml is missing, and respond by deleting the service automatically during continuous deployment? in my local test, the service remains floating around</p>

<p>does the developer have to know to connect <code>kubectl</code> to the production cluster and delete the service manually, in addition to deleting the yaml definition?</p>

<p>is there a mechanism for kubernetes to "know what's missing"?</p>

ChaseMoskal
<p>There's no such way. You can deploy resources from yaml file from anywhere if you can reach the node and configure kube config. So kubernetes will not know how to respond on a file deletion. If you still want to do this, you can write a program (a go code) which checks the availability of files in one place and deletes the corresponding resource whenever the file gets deleted.</p>

<p>There's one way via kubernetes is by using kubernetes operator, and whenever there is any change in your files you can update the crd used to deploy resources via operator. </p>
