<p>I have the following command:</p>
<pre><code>kubectl delete -n vnamespace secret --field-selector type=my_secret
</code></pre>
<p>this works fine but delete all secrets. I want to delete secrets older than 24 hours. How can I add it?</p>

Slava
<p>You can use <code>jq</code> to parse kubectl output and list all secrets older than 24h, and pass it to delete.</p>
<pre class="lang-sh prettyprint-override"><code>kubectl delete secret -n vnamespace $(kubectl -n vnamespace get secrets --field-selector type=my_secret -o json | jq -r &quot;[.items[] | {name: .metadata.name, startTime: .metadata.creationTimestamp | fromdate } | select(.startTime &lt; (now | . - 86400))]&quot; | jq -r &quot;.[].name&quot;)
</code></pre>
