命令kubectl get ns或者kubectl get namespaces 案例:
[root@123 ~]# kubectl get namespaces NAME STATUS AGE default Active 3h40m kube-node-lease Active 3h40m kube-public Active 3h40m kube-system Active 3h40m
#使用yaml创建名称空间 [root@123 ~]# kubectl create -f test-namespace.yaml test-ns created [root@123 ~]# kubectl get ns NAME STATUS AGE default Active 3h45m kube-node-lease Active 3h45m kube-public Active 3h45m kube-system Active 3h45m test-ns Active 18s# 使用命令创建名称空间 [root@123 ~]# kubectl create namespace custom-namespace custom-namespace created [root@123 ~]# kubectl get ns NAME STATUS AGE custom-namespace Active 11s default Active 3h49m kube-node-lease Active 3h49m kube-public Active 3h49m kube-system Active 3h49m test-ns Active 4m1s [root@123 ~]# kubectl describe ns custom-namespace Name: custom-namespace Labels: kubernetes.io/metadata.name=custom-namespace Annotations: Status: Active No resource quota. No LimitRange resource.
注意:命名空间名称不允许包含点(.)
删除namespace
命令:kubectl delete ns $namespace 案例:
[root@123 ~]# kubectl get ns NAME STATUS AGE custom-namespace Active 11s default Active 3h49m kube-node-lease Active 3h49m kube-public Active 3h49m kube-system Active 3h49m test-ns Active 4m1s[root@123 ~]# kubectl delete ns custom-namespacenamespace"custom-namespace" deleted[root@123 ~]# kubectl get ns NAME STATUS AGE default Active 3h55m kube-node-lease Active 3h55m kube-public Active 3h55m kube-system Active 3h55m test-ns Active 10m