Welcome to our latest blog post, where we delve into the world of Kubernetes Namespace. Whether you're new to Kubernetes or a seasoned pro, this guide will equip you with why we need namespaces. Let's get started!
What are Namespaces?
Think of a Kubernetes cluster like a big playground with many toys. A namespace is like a separate area of the playground where you and your friends can play with your own toys.
In the same way, Kubernetes namespaces create separate areas in the cluster where you can run your applications without them bumping into each other. Each namespace has its own set of resources like apps, storage, and network that are unique to that namespace. This keeps things organized and prevents conflicts between different groups of people or projects using the same cluster.
So, namespaces help keep order in the Kubernetes playground by giving different groups their own space to play without getting in each other's way.
Now that you know what is kubernetes and why we need but if you have still any confusion then let me give you a very simple example.
Suppose you have a folder in your PC named "Marvel Movies" and another folder named "DC Movies". In the Marvel Movies folder, you keep all movies of marvel and in the DC folder, you keep all DC movies.
So this Movies folder name is just like a namespace.
What is the benefit of a namespace?
Organization: You can keep your stuff (applications and resources) in your own room (namespace), making it easy to find and manage.
Isolation: Your room is your space; what happens there doesn't affect other rooms. Similarly, your resources in a namespace don't interfere with resources in other namespaces.
Security: You can lock your room (set access controls) to control who can enter and what they can do. Namespaces provide security boundaries.
Clarity: It's clear who owns each room (namespace), which helps teams or projects work independently without confusion.
So, namespaces help organize, isolate, secure, and clarify things in a Kubernetes cluster, just like rooms in a house do for people and their belongings.
Let's Create some Namespaces
Now we will create a namespace the syntax for that is kubectl create namespace <namespace_name>
we will create two namespaces which are frontend and backend
Now check both the namespace with syntax kubectl get namespace
will show all the namespaces.
As you can both of our newly created namespaces are there. but we have also some namespaces that we did not even create.
default: For objects that have no other namespace
kube-system: For Kubernetes-created objects
kube-public: For resources that need to be publically available
kube-node-lease: For objects related to cluster scaling
This namespace is created by default when Kubernetes users are cared for.
All the Commands
These are the commands that you will use mostly when you deal with namespaces.
kubectl create namespace <namespace_name>
– Create a namespace.
kubectl get namespace <namespace_name>
– List one or more namespaces.
kubectl describe namespace <namespace_name>
– Display the detailed state of one or more namespaces.
kubectl delete namespace <namespace_name>
– Delete a namespace.
kubectl edit namespace <namespace_name>
– Edit and update the definition of a namespace.
kubectl top namespace <namespace_name>
– Display Resource (CPU/Memory/Storage) usage for a namespace.
THE END
That is all for today we learned a lot today if you have any questions please let me I will answer that. One more suggestion please write down those commands on a piece of paper that will be always on your table so that whenever you need it you can refer from that.