kubectl:描述与获取 -o <格式>

Dag*_*ang 16 kubernetes kubectl

在kubectl中,describeget -o <format>都可以用来获取资源的详细信息,我想知道两者有什么区别?describe如果get可以做同样的事情甚至更多,为什么会存在?

Tum*_*nvi 10

  • kubectl get默认显示表格。(您可以轻松查看/可视化大量对象)

  • kubectl describe显示详细说明。(更适合单个对象)

  • kubectl describe 比给出的完整对象数据更扁平,数据更少,更容易阅读 kubectl get -o yaml



帮助输出以供参考。

kubectl describe -h

Show details of a specific resource or group of resources

 Print a detailed description of the selected resources, including related resources such as events or controllers. You
may select a single object by name, all objects of that type, provide a name prefix, or label selector. For example:

  $ kubectl describe TYPE NAME_PREFIX

 will first check for an exact match on TYPE and NAME_PREFIX. If no such resource exists, it will output details for
every resource that has a name prefixed with NAME_PREFIX.

Use "kubectl api-resources" for a complete list of supported resources.
Run Code Online (Sandbox Code Playgroud)

kubectl get -h

Display one or many resources

 Prints a table of the most important information about the specified resources. You can filter the list using a label
selector and the --selector flag. If the desired resource type is namespaced you will only see results in your current
namespace unless you pass --all-namespaces.

 Uninitialized objects are not shown unless --include-uninitialized is passed.

 By specifying the output as 'template' and providing a Go template as the value of the --template flag, you can filter
the attributes of the fetched resources.

Use "kubectl api-resources" for a complete list of supported resources.
Run Code Online (Sandbox Code Playgroud)


Eya*_*vin 9

一个简单的解释可能是:

kubectl describe ..== 过滤kubectl get .. -o <format>+ 相关事件


出于调试目的,查看两者很有用describeget -o <format>因为每个都有相关信息,而另一个未显示。

请注意,还可以通过运行kubectl get events(对于默认命名空间)或kubectl get event --all-namespaces(对于所有命名空间)来显示事件。


一些挖掘:

kubectl describe使用扩展日志运行--v=8显示它events使用involvedObject.name%3Dsome-pod.

$ kubectl --v=8 describe pod some-pod 2>&1 | grep GET
I1216 17:09:00.453529    6918 round_trippers.go:416] GET https://100.190.50.200/api/v1/namespaces/default/pods/some-pod
I1216 17:09:01.098053    6918 round_trippers.go:416] GET https://100.190.50.200/api/v1/namespaces/default/pods/some-pod
I1216 17:09:01.265924    6918 round_trippers.go:416] GET https://100.190.50.200/api/v1/namespaces/default/events?fieldSelector=involvedObject.name%3Dsome-pod%2CinvolvedObject.namespace%3Ddefault%2CinvolvedObject.uid%3Dbf664be1-1cde-11ea-bce6-42010af00267
Run Code Online (Sandbox Code Playgroud)

kubectl get pod some-pod -o yaml只调用podsAPI。

kubectl --v=8 get pod some-pod -o yaml 2>&1 | grep GET
I1216 17:13:21.084386   28256 round_trippers.go:416] GET https://100.190.50.200/api/v1/namespaces/default/pods/some-pod
Run Code Online (Sandbox Code Playgroud)


Dav*_*dPi 5

根据 Kubernetes 文档:

kubectl -n <NAMESPACE> get <NAME_OF_RESOURCE>
Run Code Online (Sandbox Code Playgroud)

打印有关指定资源的最重要信息的表。您可以使用标签选择器和 --selector 标志过滤列表。如果所需的资源类型是命名空间的,除非您传递 --all-namespaces,否则您只会看到当前命名空间中的结果。来源:https : //kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get

kubectl -n <NAMESPACE> describe <NAME_OF_RESOURCE>
Run Code Online (Sandbox Code Playgroud)

打印所选资源的详细说明,包括相关资源,例如事件或控制器。您可以按名称选择单个对象、该类型的所有对象、提供名称前缀或标签选择器。来源:https : //kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe

kubectl describe 应该给你更多的信息。即使,我同意你的看法,一些资源已经用 kubectl get 或 kubectl describe 安静了相同的信息。