Kubernetes namespaces offer a simple but powerful way to isolate resources in a shared cluster. By creating separate namespaces for each tenant, you can control which users have access to which resources, and limit the visibility of resources between tenants.
You can create a namespace by running the kubectl create namespace
command. For example, to create a namespace for a tenant called acme
, you would run:
kubectl create namespace acme
Once a namespace has been created, you can assign resources to it using the --namespace
flag with the kubectl
command. For example, to create a pod in the acme
namespace, you would run:
kubectl create pod --namespace acme ...
By default, the kubectl
command will only show resources in the default
namespace. To view resources in a different namespace, you can use the --namespace
flag with the kubectl get
command. For example, to view all pods in the acme
namespace, you would run:
kubectl get pods --namespace acme
If you find yourself frequently running commands in a specific namespace, you can use the kubectl config set-context
command to switch between namespaces. For example, to switch to the acme
namespace, you would run:
kubectl config set-context $(kubectl config current-context) --namespace=acme
You can delete a namespace by running the kubectl delete namespace
command. For example, to delete the acme
namespace, you would run:
kubectl delete namespace acme
Kubernetes namespaces offer a simple but powerful way to isolate resources in a shared cluster. By creating separate namespaces for each tenant, you can control which users have access to which resources, and limit the visibility of resources between tenants.