<p>When applying an update to a kubernetes resource with <code>kubectl -f apply</code> and in the applied configuration I removed some annotations that currently exists in the deployed resource, these annotations are not being removed (but the changes in the existing ones are being properly updated). How can I force to delete the removed annotations in the update process?</p>

<p>BTW, I want avoid to delete and recreate the resource</p>

<p>As @Matt mentioned</p>

<blockquote>
  <p>Did you use kubectl apply to create this data on the resource? apply stores previous state in an annotation. If that annotation doesn't exist then it can't detect what data to delete</p>
</blockquote>

<p>More about it <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#how-apply-calculates-differences-and-merges-changes" rel="nofollow noreferrer">here</a></p>

<hr>

<p>You can use <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#edit" rel="nofollow noreferrer">kubectl edit</a> to delete those annotations.</p>

<blockquote>
  <p>Edit a resource from the default editor.</p>
  
  <p>The edit command allows you to directly edit any API resource you can retrieve via the command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. You can edit multiple objects, although changes are applied one at a time. The command accepts filenames as well as command line arguments, although the files you point to must be previously saved versions of resources.</p>
  
  <p>Editing is done with the API version used to fetch the resource. To edit using a specific API version, fully-qualify the resource, version, and group.</p>
  
  <p>The default format is YAML. To edit in JSON, specify "-o json".</p>
  
  <p>The flag --windows-line-endings can be used to force Windows line endings, otherwise the default for your operating system will be used.</p>
  
  <p>In the event an error occurs while updating, a temporary file will be created on disk that contains your unapplied changes. The most common error when updating a resource is another editor changing the resource on the server. When this occurs, you will have to apply your changes to the newer version of the resource, or update your temporary saved copy to include the latest resource version.</p>
</blockquote>

<hr>

<p>I made an example with nginx pod and some annotation</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: annotations-demo
  annotations:
    delete: without-restart
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
</code></pre>

<p>I used </p>

<ul>
<li><p><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe" rel="nofollow noreferrer">kubectl describe</a> to check if the annotation is added. </p>

<blockquote>
  <p>Annotations:        delete: without-restart</p>
</blockquote></li>
<li><p><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#edit" rel="nofollow noreferrer">kubectl edit</a> to delete this annotation, it's empty now.</p>

<blockquote>
  <p>Annotations:</p>
</blockquote></li>
</ul>
