Steps to create Custom Namespace in the Kubernetes

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 cluster in our demo environment.

 

CREATE A CUSTOM NAMESPACE THROUGH KUBECTL

  • Log in to the master server through putty.

Steps to create Custom Namespace in the Kubernetes

 

  • Use this command to list all the available namespaces in your environment.

kubectl get namespaces

Steps to create Custom Namespace in the Kubernetes

 

  • To create a namespace, use kubectl create command.

Syntax: kubectl create namespace <namespace name>

Example: kubectl create namespace aznamespace

Steps to create Custom Namespace in the Kubernetes

 

  • Command executed successfully.

Steps to create Custom Namespace in the Kubernetes

 

  • Verify the new namespace.

Steps to create Custom Namespace in the Kubernetes

 

CREATE A CUSTOM NAMESPACE THROUGH YAML

  • Create a new file and add the below coding.

Steps to create Custom Namespace in the Kubernetes

apiVersion: v1
kind: Namespace
metadata:
   name: custom-namespace

Steps to create Custom Namespace in the Kubernetes

 

  • Save and close the file.
  • Use the below command to create a namespace using YAML file.

kubectl apply -f ns.yml

Steps to create Custom Namespace in the Kubernetes

 

  • Command executed successfully.

Steps to create Custom Namespace in the Kubernetes

 

  • Verify the new custom namespace.

Steps to create Custom Namespace in the Kubernetes

 

CREATE A NEW POD IN CUSTOM NAMESPACE

  • Use the kubectl command to create a POD

Syntax: kubectl run <pod name> --image=<image name> --port=<container port> --generator=run-pod/v1 -n <namespace name>

Example: kubectl run ns-pod --image=nginx --port=80 --generator=run-pod/v1 -n aznamespace

Steps to create Custom Namespace in the Kubernetes

 

  • Command executed successfully.

Steps to create Custom Namespace in the Kubernetes

 

  • Verify the pod details using the below command.

Syntax: kubecl get pods --namespace <namespace name>

Example: kubectl get pods --namespace aznamespace

Steps to create Custom Namespace in the Kubernetes

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 <namespace name>

Example: kubectl delete pods --all --namespace aznamespace

Steps to create Custom Namespace in the Kubernetes

 

  • Verify the POD availability in your custom namespace.

Steps to create Custom Namespace in the Kubernetes

 

  • To delete a namespace.

Syntax: kubectl delete namespace <namespace name>

Example: kubectl delete namespace aznamespace

Steps to create Custom Namespace in the Kubernetes

 

  • Verify the available namespaces in your environment.

Steps to create Custom Namespace in the Kubernetes

Steps to create Custom Namespace in the Kubernetes

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.



Author: Loges
Logeswaran holds Microsoft certified engineer & solution architect certifications with over 11+ years of experience in the fields of hosting technologies and IMS/Cloud consulting. At AssistanZ, Logeswaran spearheads the strategic planning and execution of the company’s Microsoft based core technologies to Enterprise clients.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.