Professional Documents
Culture Documents
How Kubernetes Namespaces Manage Cluster Resources PDF
How Kubernetes Namespaces Manage Cluster Resources PDF
Kubernetes uses the namespaces concept to deal with the complex objects
organizing within a cluster. Name spaces allow users to gather objects together to
filter and control them as a unit. Learn Kubernetes online course more
effectively.
Moreover, the user needs a Kubernetes cluster, and the kubectl command-line
tool must be arranged to contact the cluster.
Functionality of Namespace
The following are the few important functions of a Namespace within Kubernetes
−
Default Namespace
By default, a cluster will represent a default namespace while setting up the
cluster. This helps to hold the default pack of Pods, Services, and Deployments
used by the cluster.
For example, you have a fresh cluster; and you can inspect the available
namespaces by performing the following:
kubectl get namespaces
Create a Namespace
Let us imagine a visual where an entity is using a shared Kubernetes cluster for
building and producing use cases.
The development team may like to manage space within the cluster. Here, they
could get a visual of the list of Pods, Services, and implements they use to build
and run applications. In this space, many resources come and go, and the
restrictions on who may not modify resources are relaxed to enable faster
development.
The operations team would like to manage space within the cluster. Here they can
implement strict protocols on who can or cannot alter the set of Pods, Services,
and Deployments that run the production site.
lithe-cocoa-92103_kubernetes
In this context, the next step defines a context for the kubectl client to work in
each name space. Besides, the values of cluster and user fields are copied from
the existing context.
kubectl config set-context dev --namespace=development \
--cluster=lithe-cocoa-92103_kubernetes \
--user=lithe-cocoa-92103_kubernetes
The following is the configuration file for a LimitRange object. The configuration
states a default CPU request and a CPU limit.
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-limit-range
spec:
limits:
- default:
cpu: 1
defaultRequest:
cpu: 0.5
type: Container
For instance, with Kubernetes namespaces, many IT teams are able to logically
separate build, test and production ecosystems. Moreover, name spaces also
provide managerial control over resources, via resource allocations and limits.
When an IT admin sets up a cluster, four different name spaces are automatically
created:
a) Default- All the resource implements without a namespace are deployed under
this name.
c) kube-public- This is open to all users with read-only access but hired for system
usage.
d) kube-node-lease- Here, all nodes include a related Lease object in this
namespace.
A Lease improves the rendition of the node heartbeats, messages that nodes pass
to the node controller to show availability - as the cluster extends.
Let's dive in-depth and understand how to work with name spaces. As a
pre-requirement, we should have a Kubernetes cluster up and running before
trying the commands/code.
Run the below commands to get the list of all namespaces, or a relevant
Kubernetes namespace:
kubectl get namespaces kubectl get namespaces <name of namespace>
Moreover, to get detail information about a name space, the describe command
is useful:
kubectl describe namespaces <name of namespace>
To create a resource within a certain namespace that already exists, send the
name of the name space as logic to the -n or -- namespace parameter in the
command:
kubectl create deployment my-nginx --image nginx --namespace webserver
The --all-namespaces switch framework will register any resources within all the
name spaces, like the below command:
kubectl get pods --all-namespaces
Nonetheless, this method doesn't provide the precise list of all the resources
within-cluster, as all resources are not arranged within a namespace. For
example, resources like nodes, cluster roles and persistent volumes, a low-level
one, are not present in any namespace. To register all those resources without
having a namespace, the following command is issued:
kubectl api-resources --namespaced=false
Praveen Kumar
Praveen Kumar
Praveen Kumar
Delete a namespace
This will also erase any Kubernetes resources under the namespace held or exist.
Namespace granularity
There, a common question I got is how many Namespaces need to create and for
what purpose? Create many Namespaces and they get in the way, but making too
few and we miss out on the benefits.
Mostly namespaces are “hidden” from one another, but they are not completely
separated as a default. Service within one Name-space can speak to another
Name-space service well. Suppose, to get team service within our Namespace, we
should contact another team’s service within another Name-space.
Moreover, The Kubernetes namespace is useful for a small team, rapidly growing
teams, large companies, and big enterprises.
Conclusion
Namespaces can help notably with arranging the Kubernetes resources and can
enhance the velocity of the teams working. That’s in this article for now. I hope
you got a fundamental idea of namespace through this article. To get more
updates and skills in this regard, one can opt for Kubernetes Online Training.