<p>I'm trying to retrieve the value for the key <code>clientSecret</code>, from my kubernetes response, but I am failing to find the correct go syntax.</p>

<p>I have tried commands like:</p>

<pre><code>kubectl get secret client-secret -o yaml --namespace magic-test -o go-template --template="{{range .items}}{{range .data}}{{.clientSecret}} {{end}}{{end}}"
</code></pre>

<p>And other variations </p>

<p>This is the yaml output of what I am trying to retrieve from</p>

<pre><code>kubectl get secret client-secret -n magic-test -o yaml 
apiVersion: v1
data:
  clientSecret: NmQQuCNFiOWItsdfOTAyMCb00MjEwLWFiNGQtNTI4NDdiNWM5ZjMx
kind: Secret
metadata:
  creationTimestamp: 2019-05-31T14:03:44Z
  name: client-secret
  namespace: magic-test
  resourceVersion: "11544532074"
  selfLink: /api/v1/namespaces/magic-test/secrets/client-secret
  uid: e72acdsfbcc-83fsdac-1sdf1e9-9sdffaf-0050dsf56b7c1fa
type: Opaque

</code></pre>

<p>How can I retrieve the value for <code>clientSecret</code>?</p>

<p>The output is not a list of items but an object or dictionary, so you can't iterate over the pipeline but you may simply index it by the keys you're interested in.</p>

<p>So simply use the template <code>{{.data.clientSecret}}</code>:</p>

<pre><code>kubectl get secret client-secret -o yaml --namespace magic-test -o go-template
    --template="{{.data.clientSecret}}"
</code></pre>
