【容器应用系列教程】Kubernetes的命名空间Namespace
一、关于namespace
命名空间
二、命名空间namespace
管理操作
1.查看所有命名空间namespace
k8s
在创建pod
的时候,如果不指定命名空间,那么默认使用default
搭建k8s
集群自动创建的容器保存在kube-system
命名空间中
[root@k8s-master ~]# kubectl get namespace
[root@k8s-master ~]# kubectl get ns #上面命令的简写
NAME STATUS AGE
default Active 2d20h
kube-node-lease Active 2d20h
kube-public Active 2d20h
kube-system Active 2d20h
2.创建命名空间namesapce
方法1
[root@k8s-master ~]# kubectl create ns test
namespace/test created
[root@k8s-master ~]# kubectl get ns
NAME STATUS AGE
default Active 2d20h
kube-node-lease Active 2d20h
kube-public Active 2d20h
kube-system Active 2d20h
test Active 5s
方法2
[root@k8s-master ~]# vim name.yml
apiVersion: v1
kind: Namespace
metadata:
name: test2
[root@k8s-master ~]# kubectl get ns
NAME STATUS AGE
default Active 2d20h
kube-node-lease Active 2d20h
kube-public Active 2d20h
kube-system Active 2d20h
test Active 3m31s
test2 Active 9s
3.删除命名空间namesapce
方法1
[root@k8s-master ~]# kubectl delete ns test
namespace "test" deleted
[root@k8s-master ~]# kubectl get ns
NAME STATUS AGE
default Active 2d20h
kube-node-lease Active 2d20h
kube-public Active 2d20h
kube-system Active 2d20h
test2 Active 107s
方法2
[root@k8s-master ~]# kubectl delete -f name.yml
namespace "test2" deleted
[root@k8s-master ~]# kubectl get ns
NAME STATUS AGE
default Active 2d20h
kube-node-lease Active 2d20h
kube-public Active 2d20h
kube-system Active 2d20h