# kubernetes – kubectl command for talking to multiple physical clusters

[*]

short answer, you can get all ns across the existing cluster in kubeconfig

for context in $(kubectl config view -o jsonpath="{.clusters[*].name}"); do kubectl config use-context$context ;
kubectl get ns;
done
#or
for context in $(kubectl config view -o jsonpath="{.clusters[*].name}"); do kubectl config use-context$context ;kubectl get ns;done

you can get all namespace from each cluster using below command (current context)

kubectl get namespace

the above will return namespace in the current context, so you have two cluster, its mean you will need two different context to get all the namespace from both cluster

A context element in a kubeconfig file is used to group access parameters under a convenient name. Each context has three parameters: cluster, namespace, and user. By default, the kubectl command-line tool uses parameters from the current context to communicate with the cluster.

organize-cluster-access-kubeconfig-context

A namespace is simply the isolation of the resources. for example

you can not create two deployments with the same name in a single namespace, because those resources are namespace scoped.

so you can deploy multiple deployment under develop, stage and production namespace.

kubernetes-namespaces

[*]
[*]