<p>I want to get a list of the names of all namespaces in a Kubernetes cluster using a kubectl command.</p>
<p>Currently, I am running the below kubectl command which gives me a list of all namespaces.</p>
<p>However, I don't want to see the 'ACTIVE' and 'AGE' columns. I just want the NAME column.</p>
<p>The reason behind this is so that I can add all of the items from the NAME column into an array for further processing.</p>
<pre><code>&gt; kubectl get namespaces
NAME                      STATUS   AGE
dread-gorge               Active   284d
dread-lagoon              Active   210d
carncier-basin            Active   164d
chantague-shallows        Active   164d
hilraine-loch             Active   311d
stangrave-waters          Active   271d
</code></pre>

Kerbol
<p><strong>Solution-1:</strong></p>
<p>Here is an alternate way:</p>
<pre><code> kubectl get ns  --no-headers -o custom-columns=&quot;:metadata.name&quot;
</code></pre>
<blockquote>
<p>-o=custom-columns=  Print a table using a comma separated list of custom columns</p>
</blockquote>
<p><strong>Solution-2:</strong></p>
<p>Another way of getting the name <em><strong>with the type of resource</strong></em>:</p>
<pre><code>kubectl get ns -o name
</code></pre>
