<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>

<p>Before deleting the yaml file, you can run <code>kubectl delete -f file.yaml</code>, this way all the resources created by this file will be deleted.</p>
<hr />
<p>However, what you are looking for, is achieving the desired state using k8s. You can do this by using tools like <a href="https://github.com/roboll/helmfile" rel="nofollow noreferrer">Helmfile</a>.</p>
<p>Helmfile, allow you to specify the resources you want to have all in one file, and it will achieve the desired state every time you run <code>helmfile apply</code></p>
