命令创建名称空间
[root@master dashboard]# kubectl create ns testnamespace/test created[root@master dashboard]# kubectl get namespaceNAME STATUS AGEdefault Active 45hkube-flannel Active 44hkube-node-lease Active 45hkube-public Active 45hkube-system Active 45hkubernetes-dashboard Active 18htest Active 3s
使用配置文件创建名称空间
[root@master dashboard]# cat create-ns.yaml apiVersion: v1 【版本】kind: Namespace 【类型】metadata: name: test-ns01 【名称】 labels: name: ns-monitor 【标签】[root@master dashboard]# kubectl apply -f create-ns.yaml [root@master dashboard]# kubectl get namespaceNAME STATUS AGEdefault Active 45hkube-flannel Active 44hkube-node-lease Active 45hkube-public Active 45hkube-system Active 45hkubernetes-dashboard Active 18htest Active 4m11stest-ns01 Active 4s
删除名称空间
命令删除[root@master dashboard]# kubectl delete ns test test-ns01namespace "test" deletednamespace "test-ns01" deletedyaml文件删除[root@master dashboard]# kubectl delete -f create-ns.yaml