- A Kubernetes namespace provides a
scopefor object names - Instead of placing all resources in a single namespace, they can be divided into multiple namespaces
- Separate namespaces allow the same resource name to be used multiple times across different namespaces
- Using multiple namespaces allows complex systems with many components to be separated into smaller
individual groups- Used to
isolate resourcesinmulti-tenantenvironments - Resource names only need to be unique within a namespace
- Two different namespaces can have resources with the same name
- Most resource types belong within a namespace, but some do not
- One of them is the
node, which isglobaland does not belong to a single namespace
- One of them is the
- Used to
- Namespaces can be used to separate unrelated resources into non-overlapping
groups- If multiple users or groups are using the same Kubernetes cluster and each manages their own resources, they should use their own unique namespaces
- This way, there is no need to be careful about modifying or deleting other users' resources!
- If multiple users or groups are using the same Kubernetes cluster and each manages their own resources, they should use their own unique namespaces
- In addition to isolating resources, namespaces are also used to
allowspecific users access to designated resources and tolimitthe computing resources available to individual users
Since a namespace is a Kubernetes resource, it can be created by submitting a YAML file to the Kubernetes API server
ex) Creating a namespace named chloe
Create the chloe-namespace.yaml file
apiVersion: v1
kind: Namespace
metadata:
name: chloeSend the file to the Kubernetes API server using the kubectl command
kubectl create -f choe-namespace.yamlYou can quickly create a namespace using the kubectl create namespace command
ex)
kubectl create namespace chloeThis means they can contain letters, numbers, dashes (-), and dots (.)!
However, namespaces and some other resources cannot contain dots (.)!
Why? Because they must not contain DNS address names!
Using namespaces allows you to separate objects into distinct groups and work with resources within a specific namespace, but it does not provide isolation for running objects
ex)
- When different users deploy pods in different namespaces, you might think that
those pods are isolated from each other and cannot communicate, but that is not necessarily the case! - Whether a namespace provides network isolation depends on the
networking solutiondeployed with Kubernetes - If the networking solution does not provide isolation between namespaces, and a pod in namespace A knows the IP address of a pod in namespace B, there are no restrictions on sending traffic such as HTTP requests to the other pod!