0

I was wondering if anyone has any ideas on the best way to create 200 namespaces within a cluster. Ideally a simple bash loop to create kubectl create namespaces would be good.

1
  • Wouldn't you want to keep track of this in a Git repo? Commented Oct 19, 2021 at 15:13

2 Answers 2

4

You can dynamically create a YAML file using any programming language you are most comfortable with (bash or python), consisting of a list of k8s namespaces with the following format:

$ cat namespaces-list.yaml
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
  kind: Namespace
  metadata:
  name: namespace-list1
- apiVersion: v1
  kind: Namespace
  metadata:
  name: namespace-list2
- apiVersion: v1
  kind: Namespace
  metadata:
  name: namespace-list3

Then execute the following command to create them all in one shot! kubectl apply -f namespaces-list.yaml

Hope this helped!

Sign up to request clarification or add additional context in comments.

Comments

1

I eventually came up with something as simple this

#!/usr/bin/env bash
  for i in $(seq 100); do
    kubectl create namespace test-${i}
         
done

Comments

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.