What is a namespace in kubernetes?
- 2 Node Cluster (1 Master VM with 2 Nodes)
- Kubernetes Components
- 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.
Creating a custom namespace through Kubectl
- The first thing we need to do is log into the master server using Putty.
- In order to list all the available namespaces in our environment use the following command.
kubectl get namespaces
- By using the kubectl create command we will be able to create a namespace in our environment.
- Hurray! We had successfully executed our command.
- After the execution of the command, verify the new namespace.
Creating a custom namespace through YAML
- Firstly, create a new file and add the below coding.
api Version: v1 kind: Namespace metadata:name: custom-namespace
- 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.
- Bingo! The command was executed smoothly as butter.
- It is necessary to verify the new custom namespace that has been created.
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.
- After the successful execution of the command, verify the POD details by using the following command.
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.
- Verify the POD availability in the custom namespace.
- To delete a namespace use the following command.
Syntax: kubectl delete namespace
Example: kubectl delete namespace aznamespace
- Verify the available namespaces in your environment.
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 (firstname.lastname@example.org).