在kubectl中,describe
和get -o <format>
均可用于获取资源的详细信息,我想知道两者之间有什么区别?如果describe
可以做同样的事情甚至更多,为什么get
甚至存在?
答案 0 :(得分:3)
根据kubernetes文档:
kubectl -n <NAMESPACE> get <NAME_OF_RESOURCE>
打印有关指定内容的最重要信息的表 资源。您可以使用标签选择器和 --selector标志。如果所需的资源类型已命名空间,则除非您通过,否则只会在当前命名空间中看到结果 --all-namespaces。 来源:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get
kubectl -n <NAMESPACE> describe <NAME_OF_RESOURCE>
打印所选资源的详细说明,包括 相关资源,例如事件或控制器。您可以选择一个 按名称的单个对象,该类型的所有对象都提供一个名称 前缀或标签选择器。 来源:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe
kubectl describe应该可以为您提供更多信息。即使我同意您的观点,有些资源还是使与kubectl get或kubectl describe相同的信息变得安静。
答案 1 :(得分:3)
帮助输出以供参考。
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.
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.
kubectl get
默认显示表格。 (您可以轻松查看/可视化大量对象)
kubectl describe
显示了详细说明。 (最好是单个对象)
kubectl describe
提供的完整对象数据相比, kubectl get -o yaml
更平整,数据更少,更易于读取
答案 2 :(得分:1)
一个简单的解释可能是:
Option Explicit
Sub Main()
Dim wb As Workbook
Dim Data, Last, Login
Dim sourceRow As Long, destRow As Long, sourceCol As Long, destCol As Long
Dim Dest As Range
Dim SharedServices As Variant
SharedServices = "manager 1, manager 3, manager 7, manager 11"
Set wb = Workbooks("Template.xlsx")
Set Dest = wb.Sheets("Full Roster").Range("A3")
With ThisWorkbook.Sheets("Full Roster")
Data = .Range("DC3", .Range("A" & Rows.Count).End(xlUp))
End With
wb.Activate
Application.ScreenUpdating = False
For sourceRow = 1 To UBound(Data)
If Data(sourceRow, 1) <> Last Then
If sourceRow > 1 Then
Dest.Select
wb.SaveCopyAs ThisWorkbook.Path & Application.PathSeparator & _
ValidFileName(Last & " - Validation.xlsx")
End If
With Sheets("Exempt Population")
.Rows(3 & ":" & .Rows.Count).ClearContents
End With
Last = Data(sourceRow, 1)
destRow = 0
End If
destCol = 0
If Data(sourceRow, 1) <> SharedServices Then
For sourceCol = 1 To UBound(Data, 2)
Dest.Offset(destRow, destCol) = Data(sourceRow, sourceCol)
destCol = destCol + 1
Next
sourceRow = sourceRow + 1
Else
'Group SharedServices into one file
End If
Next
SaveCopy wb, Login, Last '<< save the last report
End Sub
==过滤的kubectl describe ..
+相关事件
出于调试目的,同时查看kubectl get .. -o <format>
和describe
可能很有用,因为每个人都有彼此未显示的相关信息。
请注意,也可以通过运行get -o <format>
(对于默认名称空间)或kubectl get events
(对于所有名称空间)来显示事件。
一些挖掘:
运行kubectl get event --all-namespaces
并进行扩展日志记录kubectl describe
表示它使用--v=8
调用了events
API(第三次调用)。
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
仅调用kubectl get pod some-pod -o yaml
API。
pods
答案 3 :(得分:1)
您可以使用以下方法获取特定资源的摘要:
您可以通过以下方式获取详细信息: