<p>I want to get the last time a secret was modified via the kube api. I cannot seem to find a way to access this information. I had a look at events but I cannot find any for Secrets.</p>
<p>An example would be I create a secret called my-secret, I then update this the next day but I want to know what time it was updated and not the creation time.</p>
<p>Any help would be great thanks.</p>

Westy10101
<p>The following command will give you the secret chronological history:</p>
<p><code>kubectl get secret &lt;name&gt; --namespace &lt;namespace&gt; --show-managed-fields -o jsonpath='{range .metadata.managedFields[*]}{.manager}{&quot; did &quot;}{.operation}{&quot; at &quot;}{.time}{&quot;\n&quot;}{end}'</code></p>
<p>Example, create a secret:
<code>kubectl create secret generic test --from-literal user=$(echo 'somebody' | base64)</code></p>
<p>Run the above command:</p>
<blockquote>
<p>kubectl-create did Update at <strong>2021-12-06T01:12:17Z</strong></p>
</blockquote>
<p>Retrieve the created secret
<code>kubectl get secret test -o yaml &gt; test.yaml</code>. Replace the value for &quot;user&quot; in the yaml with <code>echo 'nobody' | base64</code> output and re-apply <code>kubectl apply -f test.yaml</code>.</p>
<p>Run the above command and it reports the last update action and timestamp:</p>
<blockquote>
<p>kubectl-create did Update at <strong>2021-12-06T01:12:17Z</strong></p>
<p>kubectl-client-side-apply did Update at <strong>2021-12-06T01:13:33Z</strong></p>
</blockquote>
<p>Now do a replace <code>kubectl patch secret test --type='json' -p='[{&quot;op&quot; : &quot;replace&quot; ,&quot;path&quot; : &quot;/data/user&quot; ,&quot;value&quot; : &quot;aGVsbG93b3JsZAo=&quot;}]'</code></p>
<p>Run the above command again:</p>
<blockquote>
<p>kubectl-create did Update at <strong>2021-12-06T01:12:17Z</strong></p>
<p>kubectl-client-side-apply did Update at <strong>2021-12-06T01:13:33Z</strong></p>
<p>kubectl-patch did Update at <strong>2021-12-06T01:21:57Z</strong></p>
</blockquote>
<p>The command correctly reports all the changes made to the secret.</p>
