Junior
What is a namespace?
sobes.tech AI
Answer from AI
A namespace in Kubernetes is a mechanism for virtual grouping of objects (pods, services, deployments, etc.) within a single cluster. It provides logical separation of resources, isolation, access control, and prevents name conflicts.
Main properties:
- Isolation: Objects in one namespace are not directly visible in another.
- Access control: RBAC policies can be applied to namespaces, restricting user or group access to resources within a specific namespace.
- Scalability: Allows organizing a cluster with many teams or applications without overlaps.
- Conflict prevention: Objects in different namespaces can have the same names.
Examples of usage:
- Separation of environments (development, staging, production).
- Division by teams or projects.
- Resource management for different applications.
Each Kubernetes cluster has predefined namespaces:
default: The default namespace for objects not explicitly specified.kube-system: For system objects created by Kubernetes.kube-public: For resources visible to all users.kube-node-lease: Contains Lease objects for tracking node availability.
# Example of creating a namespace
apiVersion: v1
kind: Namespace
metadata:
name: my-app
# Switching context to a namespace
kubectl config set-context --current --namespace=my-app
# Viewing objects in a specific namespace
kubectl get pods -n my-app
# Viewing all namespaces
kubectl get namespaces