Home > OS >  Get Only Names Of All Namespaces Kubectl - Kubernetes
Get Only Names Of All Namespaces Kubectl - Kubernetes

Time:11-24

I want to get a list of the names of all namespaces in a Kubernetes cluster using a kubectl command.

Currently, I am running the below kubectl command which gives me a list of all namespaces.

However, I don't want to see the 'ACTIVE' and 'AGE' columns. I just want the NAME column.

The reason behind this is so that I can add all of the items from the NAME column into an array for further processing.

> 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

CodePudding user response:

using jsonpath from kubectl cheatsheet

kubectl get ns -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
default
gitlab-runner
kube-node-lease
kube-public
kube-system
  • Related