Can we create multiple namespaces from command line using kubectl

7/3/2019

I want to create multiple namespace from command line using kubectl. i dont want to create them from YAML manifest. say,

kubectl create ns app1,app2,app3

can this be done?

-- P Ekambaram
kubectl
kubernetes

2 Answers

7/3/2019

You could chain together 2 kubectl commands like so:

kubectl create ns app1 && kubectl create ns app2...
-- Paul Back
Source: StackOverflow

7/3/2019

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
-- Markus Dresch
Source: StackOverflow