当前位置:   article > 正文

kubernetes中显示所有命名空间中的deployment、Pod以及所有的Pod对应的命名空间_kubectl 查询 deployments 对应的命名空间

kubectl 查询 deployments 对应的命名空间


博主的操作显得有点鸡肋了。如果有更好的欢迎留言。
在默认的命名空间namespace中查看所有的Pod显示没有找到,加入-A参数表示查看所有命名空间(namesqpace)上的Pod。

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

[root@master redis-demo]# kubectl get pods
No resources found.
[root@master redis-demo]# kubectl get pods -A
NAMESPACE       NAME                                        READY   STATUS              RESTARTS   AGE
ingress-nginx   nginx-ingress-controller-688987f6c9-tndbc   1/1     Running             6          8d
jenkins         jenkins-0                                   1/1     Running             5          7d15h
kube-system     coredns-5c98db65d4-nfvxv                    1/1     Running             10         21d
kube-system     coredns-5c98db65d4-xm9nr                    1/1     Running             10         21d
kube-system     etcd-master                                 1/1     Running             10         21d
kube-system     kube-apiserver-master                       1/1     Running             10         21d
kube-system     kube-controller-manager-master              1/1     Running             11         21d
kube-system     kube-flannel-ds-nfxth                       1/1     Running             13         21d
kube-system     kube-flannel-ds-q58bw                       1/1     Running             14         21d
kube-system     kube-flannel-ds-tszlp                       1/1     Running             10         21d
kube-system     kube-proxy-j7ds7                            1/1     Running             10         21d
kube-system     kube-proxy-khj57                            1/1     Running             8          21d
kube-system     kube-proxy-mfhlv                            1/1     Running             8          21d
kube-system     kube-scheduler-master                       1/1     Running             10         21d
nginx-demo      vol-emptydir-pod                            2/2     Running             0          5h11m
redis-demo      vol-redis-pod                               0/1     ContainerCreating   0          3h55m
[root@master redis-demo]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

过滤掉系统的

方法一:

[root@master redis-demo]# kubectl get pod -A |grep -v kube-system
NAMESPACE       NAME                                        READY   STATUS              RESTARTS   AGE
ingress-nginx   nginx-ingress-controller-688987f6c9-tndbc   1/1     Running             6          8d
jenkins         jenkins-0                                   1/1     Running             5          7d15h
nginx-demo      vol-emptydir-pod                            2/2     Running             0          5h29m
redis-demo      vol-redis-pod                               0/1     ContainerCreating   0          4h12m
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

想看所有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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

或者过滤掉系统中的Pod

[root@master redis-demo]# kubectl get pod -A -o yaml |grep '^    n'|grep -v nodeSelector|sed 'N;N;s/\n/ /g'|grep -v kube-system
    name: nginx-ingress-controller-688987f6c9-tndbc     namespace: ingress-nginx     nodeName: node2
    name: jenkins-0     namespace: jenkins     nodeName: node1
    name: vol-emptydir-pod     namespace: nginx-demo     nodeName: node2
    name: vol-redis-pod     namespace: redis-demo     nodeName: node2
  • 1
  • 2
  • 3
  • 4
  • 5

查看所有命名空间中的deployment

同理查看所有namespace中的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
  • 1
  • 2
  • 3
  • 4

哪个Deployment对应哪些Pod?????




  • 1
  • 2
  • 3

附上中文、英文版使用说明

Examples:
  # List all pods in ps output format.
  kubectl get pods
  
  # List all pods in ps output format with more information (such as node name).
  kubectl get pods -o wide
  
  # List a single replication controller with specified NAME in ps output format.
  kubectl get replicationcontroller web
  
  # List deployments in JSON output format, in the "v1" version of the "apps" API group:
  kubectl get deployments.v1.apps -o json
  
  # List a single pod in JSON output format.
  kubectl get -o json pod web-pod-13je7
  
  # List a pod identified by type and name specified in "pod.yaml" in JSON output format.
  kubectl get -f pod.yaml -o json
  
  # List resources from a directory with kustomization.yaml - e.g. dir/kustomization.yaml.
  kubectl get -k dir/
  
  # Return only the phase value of the specified pod.
  kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}
  
  # List resource information in custom columns.
  kubectl get pod test-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image
  
  # List all replication controllers and services together in ps output format.
  kubectl get rc,services
  
  # List one or more resources by their type and names.
  kubectl get rc/web service/frontend pods/web-pod-13je7

Options:
  -A, --all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
      --chunk-size=500: Return large lists in chunks rather than all at once. Pass 0 to disable. This flag is beta and may change in the future.
      --field-selector='': Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.
  -f, --filename=[]: Filename, directory, or URL to files identifying the resource to get from a server.
      --ignore-not-found=false: If the requested object does not exist the command will return exit code 0.
  -k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
  -L, --label-columns=[]: Accepts a comma separated list of labels that are going to be presented as columns. Names are case-sensitive. You can also use multiple flag options like -L label1 -L label2...
      --no-headers=false: When using the default or custom-column output format, don't print headers (default print headers).
  -o, --output='': Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
      --raw='': Raw URI to request from the server.  Uses the transport specified by the kubeconfig file.
  -R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
      --server-print=true: If true, have the server return the appropriate table output. Supports extension APIs and CRDs.
      --show-kind=false: If present, list the resource type for the requested object(s).
      --show-labels=false: When printing, show all labels as the last column (default hide labels column)
      --sort-by='': If non-empty, sort list types using this field specification.  The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
  -w, --watch=false: After listing/getting the requested object, watch for changes. Uninitialized objects are excluded if no object name is provided.
      --watch-only=false: Watch for changes to the requested object(s), without listing/getting first.

Usage:
  kubectl get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

unknown flag: --all

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

中文

  #以ps输出格式列出所有Pod。
  kubectl得到豆荚
  
  #以ps输出格式列出所有Pod,并提供更多信息(例如节点名称)。
  kubectl得到豆荚-o宽
  
  #以ps输出格式列出具有指定名称的单个复制控制器。
  kubectl获取replicationcontroller网站
  
  #在“ apps” API组的“ v1”版本中以JSON输出格式列出部署:
  kubectl获取deployments.v1.apps -o json
  
  #以JSON输出格式列出单个Pod。
  kubectl get -o json pod web-pod-13je7
  
  #以JSON输出格式列出通过“ pod.yaml”中指定的类型和名称标识的Pod。
  kubectl get -f pod.yaml -o json
  
  #使用kustomization.yaml从目录中列出资源-例如dir / kustomization.yaml。
  kubectl获取-k目录/
  
  #仅返回指定Pod的相位值。
  kubectl get -o template pod / web-pod-13je7 --template = {{。status.phase}}
  
  #在自定义列中列出资源信息。
  kubectl get pod test-pod -o custom-columns = CONTAINER:.spec.containers [0] .name,IMAGE:.spec.containers [0] .image
  
  #以ps输出格式一起列出所有复制控制器和服务。
  kubectl get rc,服务
  
  #按类型和名称列出一个或多个资源。
  kubectl获取rc / web服务/前端pods / web-pod-13je7

选项:
  -A,--all-namespaces = false:如果存在,则在所有命名空间中列出请求的对象。即使使用--namespace指定,当前上下文中的命名空间也将被忽略。
      --allow-missing-template-keys = true:如果为true,则当模板中缺少字段或映射键时,忽略模板中的任何错误。仅适用于golang和jsonpath输出格式。
      --chunk-size = 500:以大块而不是一次全部返回大列表。传递0禁用。该标志是beta,将来可能会更改。
      --field-selector ='':要过滤的选择器(字段查询),支持'=','=='和'!='(例如--field-selector key1 = value1,key2 = value2)。该服务器仅支持每种类型有限数量的字段查询。
  -f,--filename = []:标识从服务器获取资源的文件的文件名,目录或URL。
      --ignore-not-found = false:如果所请求的对象不存在,该命令将返回退出代码0。
  -k,--kustomize ='':处理kustomization目录。该标志不能与-f或-R一起使用。
  -L,--label-columns = []:接受以逗号分隔的标签列表,这些标签将作为列显示。名称区分大小写。您还可以使用多个标志选项,例如-L label1 -L label2 ...
      --no-headers = false:使用默认或自定义列输出格式时,请勿打印标题(默认打印标题)。
  -o,--output ='':输出格式下列之一:json | yaml | wide | name | custom-columns = ... | custom-columns-file = ... | go-template = ... | go-template-file = ... | jsonpath =。 .. | jsonpath-file = ...参见自定义列[http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns]、golang模板[http://golang.org/pkg / text / template /#pkg-overview]和jsonpath模板[http://kubernetes.io/docs/user-guide/jsonpath]。
      --raw ='':要从服务器请求的原始URI。使用kubeconfig文件指定的传输方式。
  -R,--recursive = false:递归处理-f,--filename中使用的目录。当您要管理在同一目录中组织的相关清单时很有用。
  -l,--selector ='':要过滤的选择器(标签查询),支持'=','=='和'!='(例如-l key1 = value1,key2 = value2)
      --server-print = true:如果为true,则让服务器返回适当的表输出。支持扩展API和CRD。
      --show-kind = false:如果存在,请列出所请求对象的资源类型。
      --show-labels = false:打印时,将所有标签显示为最后一列(默认为隐藏标签列)
      --sort-by ='':如果非空,则使用此字段规范对列表类型进行排序。字段规范表示为JSONPath表达式(例如'{.metadata.name}')。此JSONPath表达式指定的API资源中的字段必须为整数或字符串。
      --template ='':-o = go-template,-o = go-template-file时要使用的模板字符串或模板文件的路径。模板格式为golang模板[http://golang.org/pkg/text/template/#pkg-overview]。
  -w,--watch = false:列出/获取请求的对象后,请注意更改。如果未提供对象名称,则排除未初始化的对象。
      --watch-only = false:无需先列出/获取,即可监视对请求对象的更改。

用法:
  kubectl get [(-o | --output =)json | yaml | wide | custom-columns = ... | custom-columns-file = ... | go-template = ... | go-template-file = ... | jsonpath = ... | jsonpath-file = ...](TYPE [.VERSION] [。GROUP] [NAME | -l标签] | TYPE [.VERSION] [。GROUP] / NAME ... )[标志] [选项]

使用“ kubectl选项”获得全局命令行选项的列表(适用于所有命令)。

未知标志:-全部

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/162060
推荐阅读
相关标签
  

闽ICP备14008679号