命令创建名称空间

  1. [root@master dashboard]# kubectl create ns test
  2. namespace/test created
  3. [root@master dashboard]# kubectl get namespace
  4. NAME STATUS AGE
  5. default Active 45h
  6. kube-flannel Active 44h
  7. kube-node-lease Active 45h
  8. kube-public Active 45h
  9. kube-system Active 45h
  10. kubernetes-dashboard Active 18h
  11. test Active 3s

使用配置文件创建名称空间

  1. [root@master dashboard]# cat create-ns.yaml
  2. apiVersion: v1 【版本】
  3. kind: Namespace 【类型】
  4. metadata:
  5. name: test-ns01 【名称】
  6. labels:
  7. name: ns-monitor 【标签】
  8. [root@master dashboard]# kubectl apply -f create-ns.yaml
  9. [root@master dashboard]# kubectl get namespace
  10. NAME STATUS AGE
  11. default Active 45h
  12. kube-flannel Active 44h
  13. kube-node-lease Active 45h
  14. kube-public Active 45h
  15. kube-system Active 45h
  16. kubernetes-dashboard Active 18h
  17. test Active 4m11s
  18. test-ns01 Active 4s

删除名称空间

  1. 命令删除
  2. [root@master dashboard]# kubectl delete ns test test-ns01
  3. namespace "test" deleted
  4. namespace "test-ns01" deleted
  5. yaml文件删除
  6. [root@master dashboard]# kubectl delete -f create-ns.yaml