Kubernetes – Namespaces
Pre-requisite:- Kubernetes
Kubernetes Namespace is a mechanism that enables you to organize resources. It is like a virtual cluster inside the cluster. A namespace isolates the resources from the resources of other namespaces. For example, You need to have different names for deployments/services in a namespace but you can have the same name for deployment in two different namespaces.
By default, Kubernetes has 4 namespaces

- kube-system: System processes like Master and kubectl processes are deployed in this namespace; thus, it is advised NOT TO CREATE OR MODIFY ANYTHING namespace.
- kube-public: This namespace contains publicly accessible data like a configMap containing cluster information.
- kube-node-lease: This namespace is the heartbeat of nodes. Each node has its associated lease object. It determines the availability of a node.
- default: This is the namespace that you use to create your resources by default.
Although whatever resources you create will be created in the default namespace but you can also create your own new namespace and create resources there.
Note: Avoid creating namespaces with the prefix kube-, since it is reserved for Kubernetes system namespaces and also you should not try to modify these namespaces.
Creating a Namespace:
You can create your namespace by using the command
$ kubectl create namespace your-namespace

As you can see we have successfully created namespace gfg.
Creating Component in a Namespace:
To create a component in a namespace you can either give the –namespace flag or specify the namespace in the configuration file.
Method 1: Using –namespace flag
$ kubectl apply -f your_config.yaml --namespace=your-namespace
then you can check resources in your namespace using kubectl get and specify namespace using -n

Method 2: Adding namespace in the configuration file
Instead of specifying a namespace using the –namespace flag you can specify your namespace initially in your config file only.

and then use the command.
$ kubectl apply -f your_config_file.yaml

Hence we have successfully created a component in the desired namespace.






Please Login to comment...