You can Watch all our Tutorials and Training Videos for Free on ourYouTube Channel

Kubernetes Namespaces Explained with Easy Examples

kubernetes tutorials, kubernetes namespaces, kubernetes namespaces explained, kubernetes namespaces examples, kubernetes namespaces best practices

This tutorial post will help you to understand everything about Kubernetes Namespaces.

In the previous posts, already we have explained the below topics related to Kubernetes. Refer those links to understand this topic from basics.

What is Kubernetes - Learn Kubernetes from Basics
Install & Configure Kubernetes Cluster with Docker on Linux
Create Kubernetes Deployment, Services & Pods Using Kubectl
Create Kubernetes YAML for Deployment, Service & Pods
What is Docker - Get Started from Basics - Docker Tutorial
What is Container, What is Docker on Container - Get Started
How to Install Docker on CentOS 7 / RHEL 7

Kubernetes Namespaces Explained with Examples

In this post, We will cover the below topics on Kubernetes namespaces.

Let's get started.

What is Kubernetes Namespaces?

Clusters can be divided into virtual sub-clusters using namespaces. When multiple teams or projects share a Kubernetes cluster, they can be useful. Within a cluster, any number of namespaces can be maintained, each logically distinct from the others yet able to communicate with one another. Within each other, namespaces cannot be nested.

Kubernetes Namespaces Explained with Easy Examples

Any resource in Kubernetes exists in one of two namespaces: the default namespace or a namespace created by the cluster operator. Outside of the namespace, only nodes and persistent storage volumes exist; these low-level resources are always visible to every namespace in the cluster.

Why Kubernetes Namespaces are used?

The following are some of the most important features of a Kubernetes Namespaces.

  1. Using the same namespace, namespaces aid pod-to-pod communication.
  2. Namespaces are virtual clusters that can be stacked on top of each other.
  3. They create a logical barrier between the teams and their surroundings.

What is "default" namespaces in Kubernetes?

Kubernetes has three default namespaces comes within the cluster. They are as follows:

default: This is the namespaces that every Kubernetes command uses by default, and where every Kubernetes resource is stored by default. The entire cluster is in 'default' until additional namespaces are created.
kube-system: This term should be avoided when referring to Kubernetes components.
kube-public: It is a resource for public use. Users are not advised to utilise it.

How to Get Namespaces available in Kubernetes?

Use kubectl command to get namespaces available in kubernetes as every resources.

[kubernetes-master ~]$ kubectl get ns

If you want to get all the resources created and available within the namespaces, specify the namespaces to get every resources as below.

To get list of pods running within the specific namespaces:

[kubernetes-master ~]$ kubectl -n test-namespace get pods

To get list of services created within the specific namespaces:

[kubernetes-master ~]$ kubectl -n test-namespace get svc

Siimlaryly, you can "get" options to list any resources created for the namespaces.

How to Create Kubernetes Namespaces?

As every resources, namespaces also can be created using command or yaml files.

Command Method:

Use "kubectl create" command to create namespaces. lets say we want to create namespace called "develop".

[kubernetes-master ~]$ kubectl create namespace develop
namespace/develop created

Where, "develop" is the namespace.

Yaml method:

Create a yaml file to create namespaces as below. Replace the namespace name in the 'name' field as you prefer to create it. in this example, lets create the namespace called "develop".

[kubernetes-master ~]$ cat develop-ns.yaml
apiVersion: v1
kind: Namespace
name: develop

Apply the created namespace yaml file.

[kubernetes-master ~]$ kubectl apply -f develop-ns.yaml
namespace/develop created

Thats all on this post about Kubernetes Namespaces.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

YouTube | Facebook | Twitter | Pinterest | Telegram

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
whatsapp logo