使用kubens管理命名空间namespace
默认的切换命名空间的命令不好用,可以使用第三方的命名空间切换工具:kubens,kubens命令所在的网站为:https://github.com/ahmetb/kubectx/releases/
下载kubens,并授予可执行权限
[root@k8scloude1 ~]# wget https://github.com/ahmetb/kubectx/releases/download/v0.9.4/kubens
[root@k8scloude1 ~]# ll -h kubens
-rw-r--r-- 1 root root 5.5K 12月 8 15:46 kubens
[root@k8scloude1 ~]# chmod +x kubens
[root@k8scloude1 ~]# mv kubens /bin/
[root@k8scloude1 ~]# ls /bin/kubens
/bin/kubens
查看所有的命名空间
[root@k8scloude1 ~]# kubens
default
kube-node-lease
kube-public
kube-system
ns1
ns2
切换namespace到kube-system
[root@k8scloude1 ~]# kubens kube-system
Context "kubernetes-admin@kubernetes" modified.
Active namespace is "kube-system".
此时,默认查询的就是kube-system命名空间下的pod
[root@k8scloude1 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-6b9fbfff44-4jzkj 1/1 Running 2 20h 10.244.251.194 k8scloude3 <none> <none>
calico-node-bdlgm 1/1 Running 1 20h 192.168.110.130 k8scloude1 <none> <none>
calico-node-hx8bk 1/1 Running 1 20h 192.168.110.128 k8scloude3 <none> <none>
calico-node-nsbfs 1/1 Running 1 20h 192.168.110.129 k8scloude2 <none> <none>
coredns-545d6fc579-7wm95 1/1 Running 1 20h 10.244.158.68 k8scloude1 <none> <none>
coredns-545d6fc579-87q8j 1/1 Running 1 20h 10.244.158.67 k8scloude1 <none> <none>
etcd-k8scloude1 1/1 Running 1 20h 192.168.110.130 k8scloude1 <none> <none>
kube-apiserver-k8scloude1 1/1 Running 1 20h 192.168.110.130 k8scloude1 <none> <none>
kube-controller-manager-k8scloude1 1/1 Running 1 20h 192.168.110.130 k8scloude1 <none> <none>
kube-proxy-599xh 1/1 Running 1 20h 192.168.110.128 k8scloude3 <none> <none>
kube-proxy-lpj8z 1/1 Running 1 20h 192.168.110.129 k8scloude2 <none> <none>
kube-proxy-zxlk9 1/1 Running 1 20h 192.168.110.130 k8scloude1 <none> <none>
kube-scheduler-k8scloude1 1/1 Running 1 20h 192.168.110.130 k8scloude1 <none> <none>
metrics-server-bcfb98c76-k5dmj 1/1 Running 0 56m 10.244.112.131 k8scloude2 <none> <none>
切换namespace到default
[root@k8scloude1 ~]# kubens default
Context "kubernetes-admin@kubernetes" modified.
Active namespace is "default".
此时,默认查询的就是default命名空间下的pod
[root@k8scloude1 ~]# kubectl get pods -o wide
No resources found in default namespace.
网友评论