4

I want to create multiple namespaces from the Kubernetes CLI (kubectl) without any YAML manifests:

kubectl create namespace app1,app2,app3

Can this be done?

2 Answers 2

3

kubectl expects exactly one namespace:

➜  / kubectl create ns
error: exactly one NAME is required, got 0

depending on your shell you could pack it into a loop. here's an example for bash and zsh:

➜  / foreach ns (ns1 ns2 ns3); kubectl create ns $ns; end
Sign up to request clarification or add additional context in comments.

Comments

1

You could chain together 2 kubectl commands like so:

kubectl create ns app1 && kubectl create ns app2...

2 Comments

is there more an elegant way
The command does not have such flags/options but @Markus' suggestion might be more fitting for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.