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)