Steps To Create Custom Namespace In The Kubernetes

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. Know more

REQUIREMENTS

  • 2 Node Cluster ( 1 Master VM with 2 Nodes)
  • Kubernetes Components

INFRASTRUCTURE OVERVIEW

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 Example: kubectl create namespace aznamespace 

Steps to create Custom Namespace in the Kubernetes
  • Command executed successfully.
  • 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.

 api Version: v1kind: Namespacemetadata: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  

  • Command executed successfully.
Steps to create Custom Namespace in the Kubernetes
  • 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.
Steps to create Custom Namespace in the Kubernetes
  • Verify the pod details using the below command.

Syntax: kubecl get pods --namespace 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 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 Example: kubectl delete namespace aznamespace 

  • Verify the available namespaces in your environment.
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.

Loges

Leave a Reply

Your email address will not be published. Required fields are marked *