<p>Is it possible to display Kubernetes (K8s) resources from multiple specified <code>namespaces</code> with <strong><em>only</em></strong> the CLI (<code>kubectl</code>)?</p>
<p>In other words, given two <code>namespaces</code> in a K8s cluster:</p>
<pre class="lang-shell prettyprint-override"><code>kubectl get namespaces \
--output=go-template \
--template='{{ range .items }}{{ .metadata.name }}{{ &quot;\n&quot; }}{{ end }}'

#=&gt;

. . .
$SOME_NAMESPACE
. . .
$ANOTHER_NAMESPACE
. . .
</code></pre>
<p>would it be possible to <code>get</code> resources (such as <code>pods</code>) from <strong>only</strong> those two <code>namespaces</code> (<code>$SOME_NAMESPACE</code> and <code>$ANOTHER_NAMESPACE</code>) using <strong><em>only</em></strong> <code>kubectl</code>?</p>
<p>Supplying the <code>--all-namespaces</code> flag and filtering using either the <code>--field-selector</code> or <code>--selector</code> flags will <strong>not</strong> work, because both flags accept only <code>=</code>, <code>==</code> and <code>!=</code> operators.</p>

<p>You may use <code>go-template</code> to print the name of the pods belonging to the two namespaces, following is an example of printing pods from the <code>test-1</code> and <code>test-2</code> namespace.</p>
<pre><code>kubectl get pod -A -o go-template='{{range .items}}{{if or (eq .metadata.namespace &quot;test-1&quot;) (eq .metadata.namespace &quot;test-2&quot;) }}{{printf &quot;%s %s\n&quot; .metadata.namespace .metadata.name}}{{end}}{{end}}'
</code></pre>
