Steps To Create Custom Namespace In The Kubernetes

What is a namespace in kubernetes?

Requirements

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

Infrastructure overview

  • In the process of creating a custom namespace in K8s, we had already installed and configured the 2 Node clusters in our demo environment.
  • To learn how to install & configure the clusters visit our blog where we explain the step-by-step process of installation and configuration of clusters.

  • The first thing we need to do is log into the master server using Putty.
Steps to create Custom Namespace in the Kubernetes
  • In order to list all the available namespaces in our environment use the following command.

kubectl get namespaces

Steps to create Custom Namespace in the Kubernetes

  • By using the kubectl create command we will be able to create a namespace in our environment.
Steps to create Custom Namespace in the Kubernetes
  • Hurray! We had successfully executed our command.
Steps To Create Custom Namespace In The Kubernetes
  • After the execution of the command, verify the new namespace.
Steps to create Custom Namespace in the Kubernetes

 Creating a custom namespace through YAML

  • Firstly, create a new file and add the below coding.
Steps To Create Custom Namespace In The Kubernetes

 api Version: v1 kind: Namespace metadata:name: custom-namespace 

Steps to create Custom Namespace in the Kubernetes
  • After successfully creating the file, save the file and close it.
  • By using the following command we are able to create a namespace using the YAML file.
Steps To Create Custom Namespace In The Kubernetes
  • Bingo! The command was executed smoothly as butter.
Steps to create Custom Namespace in the Kubernetes
  • It is necessary to verify the new custom namespace that has been created.
Steps To Create Custom Namespace In The Kubernetes

 

Creating a new POD in the custom namespace

  • Before jumping to create a POD, we made your work easy. Use the following Kubectl command for the creation of a POD.
Steps To Create Custom Namespace In The Kubernetes
  • After the successful execution of the command, verify the POD details by using the following command.
Steps to create Custom Namespace in the Kubernetes
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

  • In order to delete all the PODs in the namespace use the following command.
Steps to create Custom Namespace in the Kubernetes
  • Verify the POD availability in the custom namespace.
Steps to create Custom Namespace in the Kubernetes
  • To delete a namespace use the following command.

Syntax: kubectl delete namespace 
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
Benefits of kubernetes namespace
Video Tutorial

Thank you for taking the time to read our blog on “How to create a custom namespace in the K8s environment?“. We hope you found the information valuable and insightful. If you find any issues with the information provided in this blog don’t hesitate to contact us (info@assistanz.com).

View Post >>

View Post >>