<p>I've created a secret okay by doing this...<code>kubectl create secret generic &lt;namespace&gt; &lt;secret-name&gt;   --from-literal=value1=xxxx --from-literal=value2=xxxx --from-literal=value3=xxxx</code></p>
<p>When I do a get command I get</p>
<pre><code>    apiVersion: v1
    data:
    value1: xxxx
    value2: xxxx 
    value3: xxxx
    kind: Secret
    metadata:
    creationTimestamp: &lt;time&gt;
    name: &lt;secret-name&gt;
    namespace: &lt;namespace&gt;
    resourceVersion: &lt;version number&gt;
    uid: &lt;alpha-numeric&gt;
    type: Opaque
</code></pre>
<p>...the thing is...I was expecting to automatically include an annotations section below where it says metadata so that it should looks more like</p>
<pre><code>    apiVersion: v1
    data:
    value1: xxxx
    value2: xxxx 
    value3: xxxx
    kind: Secret
    metadata:
      annotations:
       kubectl.kubernetes.io/last-applied-configuration: |
       {&quot;apiVersion&quot;:&quot;v1&quot;,&quot;data&quot;:{&quot;value1&quot;:&lt;value1&gt;,&quot;value2&quot;:&lt;value2&gt; ,&quot;value3&quot; &lt;value3&gt;},&quot;kind&quot;:&quot;Secret&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;name&quot;:&quot;&lt;secret-name&gt;&quot;,&quot;namespace&quot;:&quot; 
      &lt;namespace&gt;&quot;},&quot;type&quot;:&quot;Opaque&quot;}
    creationTimestamp: &lt;time&gt;
    name: &lt;secret-name&gt;
    namespace: &lt;namespace&gt;
    resourceVersion: &lt;version number&gt;
    uid: &lt;alpha-numeric&gt;
    type: Opaque
</code></pre>
<p>Is this ONLY possible if you add the secret from a file or is there away you can add this annotation information via the string literal..I've been searching the internet but the only solution I can find is via a file...not through a string as such....can anybody help?</p>

Mick8695
<blockquote>
<p>Is this ONLY possible if you add the secret from a file</p>
</blockquote>
<p>yes, this is used to compare the live manifest and manifest in the file.
<strong>But we annotate the secret even if it's created without a manifest file.</strong></p>
<blockquote>
<p>The kubectl apply command writes the contents of the configuration file to the kubectl.kubernetes.io/last-applied-configuration annotation. This is used to identify fields that have been removed from the configuration file and need to be cleared from the live configuration.</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#merge-patch-calculation" rel="nofollow noreferrer">merge-patch-calculation</a></p>
<p>so for example if we created secrets like</p>
<pre><code> kubectl create secret generic test  --from-literal=value1=xxxx
</code></pre>
<p>and now we want to patch this secrets with manifest file, we will get a warning <code>&quot;Warning: resource secrets/test is missing the kubectl.kubernetes.io/last-applied-configuration&quot;</code></p>
<pre><code>apiVersion: v1
data:
  value1: eHh4eA==
kind: Secret
metadata:
  name: test
  namespace: playground-account-app
type: Opaque
</code></pre>
<p>and if we tried to apply this we will get warning</p>
<pre><code>Warning: resource secrets/test is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
</code></pre>
<p><strong>Avoid these warning</strong>:</p>
<p>The above warning is because of missing the annotation but we can annotate the object in the Kubernetes to fix and avoid these warning</p>
<p><a href="https://kubernetes.io/blog/2021/04/20/annotating-k8s-for-humans/#kubernetes-annotations" rel="nofollow noreferrer">kubernetes-annotations</a></p>
<pre><code> kubectl annotate secret test --overwrite  kubectl.kubernetes.io/last-applied-configuration='{&quot;apiVersion&quot;:&quot;v1&quot;,&quot;data&quot;:{&quot;value1&quot;:&quot;eHh4eA==&quot;},&quot;kind&quot;:&quot;Secret&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;name&quot;:&quot;test&quot;,&quot;namespace&quot;:&quot;namespace-name&quot;},&quot;type&quot;:&quot;Opaque&quot;}'
</code></pre>
