<p>In my kubernetes deployment file I have a annotation as below</p>
<pre><code>spec:
  template:
    metadata:
      annotations:
        prometheus.io/port: &quot;24231&quot;
        prometheus.io/scrape: &quot;true&quot;
</code></pre>
<p>But when i apply the deployment file it will be replaced with</p>
<pre><code>spec:
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: my-app
        version: 4.0.5-164
</code></pre>
<p>Not sure why my annotations are not coming. It is getting replaced with data from a metadata section as shown below</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: my-app
    appid: xxxxx-xxxx-xxxx
    groupid: DEFAULT
    version: 4.0.5-164
</code></pre>
<p>K8s version 1.18</p>

<p>you are showing us different parts of the deployment manifest here, so I think you are confusing the different metadata sections in the same file.</p>
<p>the first section, <code>.metadata</code>, is applied to the deployment itself.</p>
<p>the <code>.spec.template.metadata</code> section is applied to the pods that are created by the deployment and those annotations will not appear in the top <code>.metadata</code> section of the deployment.</p>
<p><strong>summary</strong>:</p>
<p>if you want to specify labels/annotations for the deployment, use the <code>.metadata</code> section.</p>
<p>if you want to specify labels/annotations that are applied to your pod, use the <code>.spec.template.metadata</code> section.</p>
<p>if you want to specify labels/annotations for both, specify them in both places.</p>
<p>example:</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name:  MYAPP
  # labels/annotations that are applied to the deployment
  labels:
    app:  MYAPP
    appid: xxxxx-xxxx-xxxx
    groupid: DEFAULT
    version: 4.0.5-164
  annotations:
    whatever: isapplied
spec:
  ...
  template:
    metadata:
      # labels/annotations that are applied to the pods
      labels:
        app:  MYAPP
        appid: xxxxx-xxxx-xxxx
        groupid: DEFAULT
        version: 4.0.5-164
      annotations:
        prometheus.io/port: &quot;24231&quot;
        prometheus.io/scrape: &quot;true&quot;
</code></pre>
