<p>I want to get the value of a specific field of a secret in a shell script.</p>

<p>From the <code>kubectl get secret</code> documentation, it seems the standard way to get a secret returns the whole thing, in a specified format, with the values base64 encoded.</p>

<p>So, to get the <code>bar</code> field of the <code>foo</code> secret, output as an unencoded string, I'm doing this:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get secret foo -o json | jq -r ".data.bar" | base64 --decode
</code></pre>

<p>That is</p>

<ul>
<li>get the whole <code>foo</code> secret as JSON</li>
<li>pipe to <code>jq</code> to read the <code>bar</code> field from the JSON</li>
<li>decode the value using <code>base64</code></li>
</ul>

<p><strong>Is there a way to do this only using <code>kubectl</code>?</strong> </p>

<p>Or an elegant way in POSIX-compliant shell that doesn't rely on any dependencies like <code>jq</code>?</p>

davnicwil
<p>Try this </p>

<pre><code>kubectl get secret foo --template={{.data.bar}} | base64 --decode
</code></pre>

<p>No need of jq.</p>
