创建空间

准备文件ns1.yaml

  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: ns1

执行apply命令

[root@cka-master yaml]# kubectl apply -f ns1.yaml 
namespace/ns1 created
[root@cka-master yaml]# kubectl get ns
NAME              STATUS   AGE
default           Active   11h
kube-node-lease   Active   11h
kube-public       Active   11h
kube-system       Active   11h
ns1               Active   16s
[root@cka-master yaml]#

删除空间

[root@cka-master yaml]# kubectl delete -f ns1.yaml 
namespace "ns1" deleted
[root@cka-master yaml]# kubectl get ns
NAME              STATUS   AGE
default           Active   12h
kube-node-lease   Active   12h
kube-public       Active   12h
kube-system       Active   12h
[root@cka-master yaml]#