In Kubernetes, namespaces are a way to divide cluster resources between multiple users (via resource quota) or to partition resources by use case or application. They provide a scope for names, avoiding naming collisions in the cluster and allowing for logical isolation of resources.
To create a namespace in Kubernetes, you can use the kubectl command-line tool, which is the primary interface for interacting with Kubernetes clusters. Here's how you can create a namespace:
kubectl create namespace <namespace_name>
Replace <namespace_name> with the desired name for your namespace. Here's an example: I will create a namespace withe name s7royce
kubectl create namespace s7royce
This command will create a new namespace with the specified name.
To verify that the namespace has been created, you can list all namespaces in the cluster using the following command:
kubectl get namespaces
This command will output a list of all namespaces in the cluster, including the one you just created.
Once you have created a namespace, you can deploy resources (such as pods, services, deployments, etc.) within that namespace, and they will be isolated from resources in other namespaces. When you run kubectl commands, you can specify the namespace context using the -n flag, like so:
kubectl get pods -n s7royce
This will list all pods in the s7royce namespace.
Namespaces are a fundamental concept in Kubernetes and are commonly used to organize and manage resources within a cluster, especially in multi-tenant environments or environments with multiple applications.