In this blog, We will show you the steps to create Custom Namespace in the Kubernetes Environment.
REQUIREMENTS
- 2 Node Cluster ( 1 Master VM with 2 Nodes)
- Kubernetes Components
INFRASTRUCTURE OVERVIEW
- We have already installed and configured the 2 Node clusters in our demo environment.
- Please check the URL https://www.assistanz.com/steps-to-install-kubernetes-cluster-manually-using-centos-7/ for more information.
CREATE A CUSTOM NAMESPACE THROUGH KUBECTL
- Log in to the master server through putty.
- Use this command to list all the available namespaces in your environment.
kubectl get namespaces
- To create a namespace, use kubectl create command.
Syntax: kubectl create namespace
Example: kubectl create namespace aznamespace
Â
- Command executed successfully.
- Verify the new namespace.

Â
CREATE A CUSTOM NAMESPACE THROUGH YAML
- Create a new file and add the below coding.
Â
api Version: v1
kind: Namespace
metadata:
name: custom-namespace
Â
- Save and close the file.
- Use the below command to create a namespace using YAML file.
kubectl apply -f ns.yml
Â
Â
- Command executed successfully.
- Verify the new custom namespace.
Â
CREATE A NEW POD IN CUSTOM NAMESPACE
- Use the kubectl command to create a POD
Syntax: kubectl run --image= --port= --generator=run-pod/v1 -n
Example: kubectl run ns-pod --image=nginx --port=80 --generator=run-pod/v1 -n aznamespace
Â
- Command executed successfully.
- Verify the pod details using the below command.
Syntax: kubecl get pods --namespace
Example: kubectl get pods --namespace aznamespace
Â
Note: Kubernetes will always list the pods from the default namespace. you need to specify the namespace name to display the objects in it.
DELETING THE NAMESPACE
- To delete all the pods in a namespace.
Syntax: kubectl delete pods --all --namespace
Example: kubectl delete pods --all --namespace aznamespace
Â
- Verify the POD availability in your custom namespace.
- To delete a namespace.
Syntax: kubectl delete namespace
Example: kubectl delete namespace aznamespace
Â
- Verify the available namespaces in your environment.
Â
EXTERNAL LINKS
https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
VIDEO
Thanks for reading this blog. We hope it was useful for you to learn about custom namespaces in Kubernetes.