<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>You need to use a CI/CD tool for Kubernetes to achieve what you need. As mentioned by <a href="https://stackoverflow.com/users/12868186/sithroo" title="121 reputation">Sithroo</a> Helm is a very good option. </p>

<blockquote>
  <p>Helm lets you fetch, deploy and manage the lifecycle of applications,
  both 3rd party products and your own.</p>
  
  <p>No more maintaining random groups of YAML files (or very long ones)
  describing pods, replica sets, services, RBAC settings, etc. With
  helm, there is a structure and a convention for a software package
  that defines a layer of YAML  <strong>templates</strong> and another layer that
  changes the templates called  <strong>values.</strong>  Values are injected into
  templates, thus allowing a separation of configuration, and defines
  where changes are allowed. This whole package is called a  <strong>Helm</strong> 
  <strong>Chart</strong>.</p>
  
  <p>Essentially you create structured application packages that contain
  everything they need to run on a Kubernetes cluster; including
  <strong>dependencies</strong> the application requires. <a href="https://medium.com/prodopsio/a-6-minute-introduction-to-helm-ab5949bf425" rel="nofollow noreferrer">Source</a> </p>
</blockquote>

<p>Before you start, I recommend you these articles explaining it's quirks and features.</p>

<p><a href="https://medium.com/@gajus/the-missing-ci-cd-kubernetes-component-helm-package-manager-1fe002aac680" rel="nofollow noreferrer">The missing CI/CD Kubernetes component: Helm package manager</a></p>

<p><a href="https://medium.com/velotio-perspectives/continuous-integration-delivery-ci-cd-for-kubernetes-using-circleci-helm-b8b0a91ef1a3" rel="nofollow noreferrer">Continuous Integration &amp; Delivery (CI/CD) for Kubernetes Using CircleCI &amp; Helm</a></p>
