Creating Namespaces

We can create a Namespace in two ways:

1. CLI Commands

Namespaces can be added to your Cluster by CLI commands. You can simply enter the following command to create a new Namespace:

kubectl create namespace my-ns

This will create a new Namespace called “my-ns”. And we can simply checkout our namespaces by the following command:

kubectl get namespaces

We can see that the “my-ns” Namespace was created.

2. Configuration file

Another better way to create a Namespace is creating a Namespaces configuration file. You can call it a better way of creating Namespaces because you have a history in your Configuration File Repository of what resources you created in the Cluster. Here is how a sample Namespace configuration file would appear to be:

apiVersion: v1
kind: Namespace
metadata:
name: development
labels:
name: development

Now you can apply this configuration file using the following command:

kubectl create -f [FILE_NAME]

Kubernetes NameSpace: Complete Guide.

In Kubernetes, Namespaces are used to organize resources. You can have multiple Namespaces in a Cluster And these Namespaces are kind of virtual Clusters of their own. The official definition of Namespace says “In Kubernetes, namespaces provide a mechanism for isolating groups of resources within a single cluster”. Within a Kubernetes Namespace, resources must have unique names, but across different Namespaces, you can have resources with the same name.

In this article, we will learn everything about Kubernetes Namespaces – from its definition and types to a tutorial that will give you practical knowledge of the topic. But before that let’s start from the basics.

Table of Content

  • Default Namespaces
  • Creating Namespaces
  • Benefits of using Namespaces
  • Characteristics of Namespaces
  • Tutorial – Creating Components in the default Namespace
  • Tutorial – Creating Components in a new Namespace
  • Conclusion
  • Understanding Kubernetes Namespaces – Theory and Tutorial- (FAQs)

Similar Reads

What is a Namespace?

In Kubernetes, Namespaces are used to organize resources. You can have multiple Namespaces in a Cluster And these Namespaces are kind of virtual Clusters of their own....

Default Namespaces

Default Namespaces are the four Namespaces that are present by default in any Kubernetes Cluster. To see these in your Namespaces you can simply enter this command:...

Creating Namespaces

We can create a Namespace in two ways:...

Benefits of using Namespaces

Now Let’s first discuss what is the need for Namespaces? when should you create them? And how you should use?...

Characteristics of Namespaces

There are several characteristics of a Namespaces that one should consider before deciding how to group and how to use Namespaces:...

Tutorial – Creating Components in the default Namespace

By default if you do not provide a Namespace to a component, then it creates them in a default namespace. So if we apply this config map component:...

Tutorial – Creating Components in a new Namespace

There are two ways of creating components, we can either do it in the CLI or we configure it in the Configuration file itself:...

Conclusion

Kubernetes Namespaces are a way to group resources in a Kubernetes Cluster. In this article, we discussed how Namespaces work, What are the default Namespaces present already in a Kubernetes Cluster. From need of Namespaces to it’s characteristics, we discussed everything. Do follow the tutorial and try creating resources in a Namespace by your own because that’s the best way to learn. Make sure to learn more about kubectx and its features....

Kubernetes Namespaces – FAQ’s

1. What is a namespace in Kubernetes?...

Contact Us