KUBERNETES
CLUSTER MANAGEMENT
What is a Kubernetes Namespace?
A Kubernetes namespace is a
way to divide cluster resources between multiple users or applications.
Namespaces are a method for partitioning a single Kubernetes cluster into
multiple virtual clusters, allowing you to organize and manage your resources
more efficiently.
Why Use Namespaces?
- Resource Management:
Helps manage resources and prevent conflicts by isolating environments.
- Access Control:
Facilitates different levels of access and permissions for different teams
or applications.
- Environment Separation: Allows the separation of different environments like
development, testing, and production within the same cluster.
- Organization:
Simplifies the organization of resources, making it easier to manage large
clusters with many resources.
Simple Terms
Imagine a Kubernetes cluster as an
apartment building, and namespaces are the individual apartments within the
building:
- Apartment Building (Cluster): The whole building represents the Kubernetes cluster.
- Apartments (Namespaces): Each apartment is a separate namespace. Different
people (teams or applications) live in different apartments, each with its
own space and resources.
- Rooms (Resources):
Within each apartment, there are rooms like the kitchen, bedroom, etc.
These rooms represent Kubernetes resources (like pods, services, and
deployments) within a namespace.
Key Points
- Isolation:
Just as each apartment is isolated from others, namespaces provide a scope
for resources, preventing interference between resources in different
namespaces.
- Shared Resources:
The apartment building’s common resources (like the lobby or gym) are
analogous to cluster-wide resources that are not specific to any
namespace.
- Access Control:
You can control who has access to which apartment, similar to how you
manage access to different namespaces.
How Do Namespaces Work in Kubernetes?
Enough of theory. Let's see namespaces
in action. The basic usage of namespaces is the same as with any other objects
in Kubernetes. It means you can execute commands like kubectl create or kubectl
get for namespaces. Let's try that.
Creation and deletion of namespaces are described in the Admin
Guide documentation for namespaces.
Viewing namespaces
You can list the current namespaces in a cluster using:
kubectl get namespace
NAME STATUS AGE
default Active 1d
kube-node-lease Active 1d
kube-public Active 1d
kube-system Active 1d
Setting the namespace for a request
To set the namespace for a current request, use the --namespace flag.
For example:
first create a unique namepace with the below
kubectl create
namespace dev
kubectl run nginx --image=nginx --namespace=<insert-namespace-name-here>
kubectl get pods
--namespace=<insert-namespace-name-here>
Setting the namespace preference
You can permanently save the namespace for all subsequent
kubectl commands in that context.
kubectl config set-context
--current --namespace=<insert-namespace-name-here>
# Validate it
kubectl config view
--minify | grep namespace:
No comments:
Post a Comment