1. namespace命名空间
- 命名空间(Namespace):kubernetes蒋资源对象逻辑上隔离,从而形成多个虚拟集群
- 应用场景:
- kubectl_get namespace
- default:默认命名空间
- kube-system:k8s系统方面的命名空间
- kube-public:公共的命名空间,谁都可以访问
- kube-node-lease:k8s内部命名空间
- 两种方法指定资源命名空间:
- 命令行加 -n
- yaml资源元数据里指定namespace字段
2. namespace命名空间查看,使用,创建
2.1 查看
[root@k8s-master ~]# kubectl get namespaces
NAME STATUS AGE
default Active 47h
kube-node-lease Active 47h
kube-public Active 47h
kube-system Active 47h
kubernetes-dashboard Active 41h
[root@k8s-master ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-5dc87d545c-nscfb 1/1 Running 0 44h
calico-node-j6rhw 1/1 Running 0 44h
calico-node-n7d6s 1/1 Running 0 44h
calico-node-x86s2 1/1 Running 0 44h
coredns-6d56c8448f-hkgnk 1/1 Running 1 47h
coredns-6d56c8448f-jfbjs 1/1 Running 0 47h
etcd-k8s-master 1/1 Running 0 47h
kube-apiserver-k8s-master 1/1 Running 1 47h
kube-controller-manager-k8s-master 1/1 Running 1 47h
kube-proxy-fhgbd 1/1 Running 0 46h
kube-proxy-l7q4r 1/1 Running 0 47h
kube-proxy-qwpjp 1/1 Running 0 46h
kube-scheduler-k8s-master 1/1 Running 1 47h
2.2 创建命名空间namespace
[root@k8s-master ~]# kubectl create namespace scajy
namespace/scajy created
2.3 使用命名空间namespace分组
[root@k8s-master ~]# kubectl create deployment test -n scajy --image=nginx
deployment.apps/test created
2.4 查询namespace分组下面的应用
[root@k8s-master ~]# kubectl get pods -n scajy
NAME READY STATUS RESTARTS AGE
test-5f6778868d-rmj2h 1/1 Running 0 70s