Adding namespaces to the cluster
In Kubernetes, namespaces provide a mechanism for isolating groups of resources within a single cluster. Kubernetes namespaces can help different teams to share a Kubernetes cluster. Each team can be granted access to only those resources in their own namespace.
Kubernetes administrator
By default, a Kubernetes cluster creates a default namespace when the cluster is created. To
create a cluster by using kubeadmz init
, see Initializing a Kubernetes cluster and a control plane.
kubectl get namespaces
NAME STATUS AGE
default Active 5d2h
kube-flannel Active 5d2h
kube-node-lease Active 5d2h
kube-public Active 5d2h
kube-system Active 5d2h
zoscp-zos-pod-admission-controller Active 5d2h
zoscp-zos-security-admission-controller Active 5d2h
The namespaces kube-system, kube-flannel, zoscp-zos-pod-admission-controller, and zoscp-zos-security-admission-controller are restricted namespaces. This means that users are restricted from creating resources on the namespaces.
Creating a new namespace in a cluster
You can create a new namespace in a cluster by using kubectl create
.
- On the command line, use the
kubectl create namespace
command to create a new namespace. For example, to create a namespace that is called development, you would run:
When the command is successful, you see the following output for this example:kubectl create namespace development
namespace "development" created
- To verify that the namespace has been created, you can use
kubectl get namespaces
. With the example of a namespace that is called development you see the following output:NAME STATUS AGE default Active 5d2h kube-flannel Active 5d2h kube-node-lease Active 5d2h kube-public Active 5d2h kube-system Active 5d2h development Active 1m zoscp-zos-pod-admission-controller Active 5d2h zoscp-zos-security-admission-controller Active 5d2h
Deleting a namespace
kubectl delete
.
For example, to delete a namespace that is called development, you would run:
kubectl delete namespace development
namespace "development" deleted
To verify that the namespace is deleted, use kubectl get namespaces
.
For more information on the parameters and flags available for kubectl
, see kubectl commands.