Open In App

How To Delete Namespace In Kubernetes?

Last Updated : 15 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Kubernetes container orchestration tool that helps in managing the containerized application in pods and provides additional features such as security, storage, and network. Kubernetes comes with a service known as a namespace that helps in working and managing of resources. In this article we are going to discuss on how to delete the namespaces in Kuberenetes.

What Is Kubernetes NameSpace?

Within a Kubernetes cluster, a Namespace can be compared to a virtual cluster. In a single Kubernetes cluster, there can be several namespaces that are conceptually segregated from one another. They can support you and your groups in terms of performance, security, and organization.

In every cluster, the default, kube-system, and kube-public namespaces are always the first three to be formed. Although it is technically possible to deploy under these namespaces, we advise against using them for your applications and instead saving them for system configuration.

  • If you perform too many deployments without the necessary information, the default is for kubernetes deployments without a namespace, which is a quick way to make a mess that will be difficult to clean up.
  • Everything about Kubernetes is related to the Kube system.

How To List All The NameSpaces In Kubernetes

  • Use the below-specified command to get a list of all the namespaces that are available in Kubernetes.
kubectl get namespaces
  • As seen in the image below, the mentioned command will list every namespace in the Kubernetes.

kubectl get namespaces

How To Create Kubernetes NameSpaces

  • There are two ways to build kubernetes NameSpaces. They are

1. Imperative way
2. Declarative way

Step 1: Imperative Way Of Creating Namespaces

  • You can use the following command to create the name sspace using the imperative command:
kubectl create namespace <nameSpaceName>

creating namespaces

  • Replace “<nameSpaceName>” with your own name.
 Note: For the name, use small letters

Method 2: Using Declarative Manifest File

  • The declarative Manifest file can be used to create the namspace using the following YAML.
apiVersion: v1
kind: Namespace
metadata:
name: <Give Your name>
labels:
team: gfgtesting

Viewing Namespace Yaml

How To Delete Kubernetes NameSpaces

  • To delete Kubernetes namespaces, you can use the kubectl command-line tool, which is the official Kubernetes command-line client. Here’s the general syntax for deleting a namespace with kubectl delete command:
kubectl delete namespace <namespace-name>

Step 1: Give a list of every namespace in the cluster of Kubernetes. Then choose the namespace that needs to be removed.

Step 2: To remove that namespece, which is displayed in the image below, use the command already given.

Kubectl delete namespaces

  • As you can see in the screenshot above, we have removed the name space gfg-test and listed every namespace.
kubectl delete namespace gfg-test

Kubernetes Namespace – FAQ’s

What Is The Difference Between Kubernetes Cluster And Namespaces?

  • Kubernetes Cluster: A Kubernetes cluster is the entire Kubernetes system that consists of a set of nodes (physical or virtual machines) that run containerized applications.
  • Kubernetes Namespace: A namespace is a way to divide cluster resources into multiple virtual clusters within the same physical cluster.

How Many Namespaces Can Kubernetes Have?

You can create as many namespaces as needed for organizing and isolating resources within the cluster.

Can I Use Two Namespaces?

Absolutely, you can use as few or as many namespaces as needed for your specific use case within a Kubernetes cluster. If your applications and services do not require complex isolation or if you are just getting started with Kubernetes, you might find that using a single namespace is sufficient.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads