What is a namespace
Namespaces help to organize resources that belong together. K8s provides a default namespace which resources are put into if no namespace is specified.
kubectl get namespace
kubectl create <nameSpacesName>
Namespace Use Cases
-
group similar resources for better visibility db namespace: all the databases monitor namespace: all monitoring tools
-
separate teams so that one does not accidentally overwrite anothers' configuration scrum-a namespace scrum-b namespace devops-namespace ops-namespace
-
separate environments in the same K8s cluster and also share common resources staging namespace dev namespace prod namespace shared namespace
-
blue/green deployments in the same cluster production-blue namespace production-green namespace shared namespace
-
access and resource limits project-a namespace - confined to the namespace with resource quotas project-b namespace - confined to the namespace with resource quotas
Limitation and Consideration for Namespaces
- you cannot access most resources from another namespace ConfigMap and Secrets even with same reference or data have to be created in the same namespace Service is an exception and can be used from other namespaces
- components which cannot be created within a namespace and are not isolated or limited to namespaces
- volumes
- nodes
Namespace Configuration
either via CLI:
kubectl apply -f <fileName> --namespace=<namespaceName
or configuration file (recommended):
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-configmap
namespace: my-namespace
data:
db_url: mysql-service.database # .database means this service name belongs to database namespace