加上-A参数表示查看所有命名空间(namesqpace)上的Pod。

查看所有命名空间中的Pod或者deployment

[root@k8smaster ~]# kubectl get pods -A
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE
kube-system   coredns-7ff77c879f-wns86            1/1     Running   0          115d
kube-system   coredns-7ff77c879f-zkc9d            1/1     Running   1          115d
kube-system   etcd-k8smaster                      1/1     Running   9          190d
kube-system   kube-apiserver-k8smaster            1/1     Running   11         190d
kube-system   kube-controller-manager-k8smaster   1/1     Running   35         190d
kube-system   kube-flannel-ds-njzv4               1/1     Running   7          190d
kube-system   kube-flannel-ds-xnlwl               1/1     Running   6          190d
kube-system   kube-flannel-ds-zmq5s               1/1     Running   7          190d
kube-system   kube-proxy-8zs27                    1/1     Running   7          190d
kube-system   kube-proxy-cmcwh                    1/1     Running   6          190d
kube-system   kube-proxy-p2pdz                    1/1     Running   8          190d
kube-system   kube-scheduler-k8smaster            1/1     Running   33         190d
raytest       my-dep-548d78dc5c-67s6d             1/1     Running   0          15h
raytest       my-dep-548d78dc5c-8gcgl             1/1     Running   0          15h
raytest       my-dep-548d78dc5c-d5ppg             1/1     Running   0          15h

 过滤掉系统命名空间

[root@k8smaster ~]# kubectl get pod -A |grep -v kube-system
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE
raytest       my-dep-548d78dc5c-67s6d             1/1     Running   0          15h
raytest       my-dep-548d78dc5c-8gcgl             1/1     Running   0          15h
raytest       my-dep-548d78dc5c-d5ppg             1/1     Running   0          15h

 看所有Pod都在哪些节点上运行

# kubectl get pod -A -o yaml |grep '^    n'|grep -v nodeSelector|awk 'NR%3==1{print ++n"\n"$0;next}1'
1
    name: nginx-ingress-controller-688987f6c9-tndbc
    namespace: ingress-nginx
    nodeName: node2
2
    name: jenkins-0
    namespace: jenkins
    nodeName: node1
3
    name: coredns-5c98db65d4-nfvxv
    namespace: kube-system
    nodeName: master
4
    name: coredns-5c98db65d4-xm9nr
    namespace: kube-system
    nodeName: master
5
    name: etcd-master
    namespace: kube-system
    nodeName: master
6
    name: kube-apiserver-master
    namespace: kube-system
    nodeName: master
7
    name: kube-controller-manager-master
    namespace: kube-system
    nodeName: master
8
    name: kube-flannel-ds-nfxth
    namespace: kube-system
    nodeName: node2
9
    name: kube-flannel-ds-q58bw
    namespace: kube-system
    nodeName: master
10
    name: kube-flannel-ds-tszlp
    namespace: kube-system
    nodeName: node1
11
    name: kube-proxy-j7ds7
    namespace: kube-system
    nodeName: master
12
    name: kube-proxy-khj57
    namespace: kube-system
    nodeName: node2
13
    name: kube-proxy-mfhlv
    namespace: kube-system
    nodeName: node1
14
    name: kube-scheduler-master
    namespace: kube-system
    nodeName: master
15
    name: vol-emptydir-pod
    namespace: nginx-demo
    nodeName: node2
16
    name: vol-redis-pod
    namespace: redis-demo
    nodeName: node2

 查看所有命名空间中的deployment

[root@master redis-demo]# kubectl get deploy -A
NAMESPACE       NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
ingress-nginx   nginx-ingress-controller   1/1     1            1           8d
kube-system     coredns                    2/2     2            2           21d

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐