3.4.1 查看名称空间及其资源对象
Kubernetes 集群默认提供了几个名称空间用于特定的目的,例如,kube-system 主要用于运行系统级资源,而default则为那些未指定名称空间的资源操作提供一个默认值,前面章节中的绝大多数资源管理操作都在 default 名称空间中进行。“kubectl get namespaces”命令则可以查看 namespaces 资源:
**[terminal]
**[delimiter $ ]**[command kubectl get namespaces]
NAME STATUS AGE
default Active 10d
kube-node-lease Active 10d
kube-public Active 10d
kube-system Active 10d
也可以使用 “kubectl describe namespaces” 命令查看特定名称空间的详细信息,例如:
**[terminal]
**[delimiter $ ]**[command kubectl describe namespaces]
Name: default
Labels: <none>
Annotations: <none>
Status: Active
No resource quota.
No resource limits.
kubectl 的资源查看命令在多数情况下应该针对特定的名称空间来进行,为其使用“-n”或“--namespace”选项即可,例如,查看kube-system下所有的Pod资源:
**[terminal]
**[delimiter $ ]**[command kubectl get pods --namespce kube-system]
NAME READY STATUS RESTARTS AGE
coredns-f8d45bc4-fs49m 1/1 Running 1 10d
coredns-f8d45bc4-tplxw 1/1 Running 1 10d
etcd-kubeedge.localdomain 1/1 Running 1 10d
kube-apiserver-kubeedge.localdomain 1/1 Running 1 10d
kube-controller-manager-kubeedge.localdomain 1/1 Running 1 10d
kube-flannel-ds-amd64-67gpx 1/1 Running 1 10d
kube-flannel-ds-amd64-rxnqv 1/1 Running 0 8d
kube-flannel-ds-amd64-txzbz 1/1 Running 0 8d
kube-flannel-ds-amd64-xz572 1/1 Running 0 8d
kube-proxy-2ppcl 1/1 Running 0 8d
kube-proxy-jjrn5 1/1 Running 0 8d
kube-proxy-l784k 1/1 Running 1 10d
kube-proxy-qfj4g 1/1 Running 0 10d
kube-proxy-sz2xp 1/1 Running 0 8d
kube-scheduler-kubeedge.localdomain 1/1 Running 1 10d
命令结果显示出 kube-system 与 default 名称空间的Pod 资源对象并不相同,这正是Namespace资源的名称隔离功能的体现。有了 Namespace 对象,用户再也不必精心安排资源名称,也不用担心误操作了其他用户的资源。