top of page

Kubernetes Namespaces

Kubernetes consists of different type of resources and sometimes we need these resources to be isolated into different groups. Namespace provides this mechanism to isolate the resources into different groups.


But few points need to be kept in mind as follow:

  • Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces. For example : namespace1 can have pod with name : webserver1 and namespace2 can have pod with same name: webserver1

  • Namespaces cannot be nested inside one another and each Kubernetes resource can only be in one namespace.

  • Namespaces are a way to divide cluster resources between multiple users. For example: you can create namespace : customer1, customer2, customer3

  • Not all kubernetes resources can be grouped inside namespaces. Use the below commands to get the details:

# kubectl api-resources --namespaced=true 

Note: The above command helps to get list of all resources which can be isolated with the help of namespace


# kubectl api-resources --namespaced=false

Note: The above command helps to get list of all resources which cannot be isolated with the help of namespace


1. Get list of namespace:

When Kubernetes gets installed there are few namespaces which gets created by default and to get the list of namespaces use the below commands:


# kubectl get namespaces
or
# kubectl get ns

2. To create a namespace:

Use the below command to create a namespace


# kubectl create namespace customer1

3. To get all resources inside any namespace:

Use the below resources to get all the resources inside a namespace:


# kubectl get all -n kube-system


3. Delete Namespace

Once a namespace is deleted, all the resources inside that namespace also gets deleted, use the below command to delete a namespace:

# kubectl delete ns customer1
14 views0 comments

Comentarios


Read More

Never miss an update

Thanks for submitting!

bottom of page