@@ -36,7 +36,7 @@ of Containers for each.
36
36
37
37
- Fetch all Pods in all namespaces using `kubectl get pods --all-namespaces`
38
38
- Format the output to include only the list of Container image names
39
- using `-o jsonpath={..image}`. This will recursively parse out the
39
+ using `-o jsonpath={.items[*].spec.containers[*] .image}`. This will recursively parse out the
40
40
`image` field from the returned json.
41
41
- See the [jsonpath reference](/docs/user-guide/jsonpath/)
42
42
for further information on how to use jsonpath.
@@ -48,7 +48,7 @@ of Containers for each.
48
48
## 列出所有命名空间下的所有容器
49
49
50
50
- 使用 ` kubectl get pods --all-namespaces ` 获取所有命名空间下的所有 Pod
51
- - 使用 ` -o jsonpath={..image} ` 来格式化输出,以仅包含容器镜像名称。
51
+ - 使用 ` -o jsonpath={.items[*].spec.containers[*] .image} ` 来格式化输出,以仅包含容器镜像名称。
52
52
这将以递归方式从返回的 json 中解析出 ` image ` 字段。
53
53
- 参阅 [ jsonpath 说明] ( /zh/docs/reference/kubectl/jsonpath/ )
54
54
获取更多关于如何使用 jsonpath 的信息。
@@ -58,7 +58,7 @@ of Containers for each.
58
58
- 使用 ` uniq ` 来聚合镜像计数
59
59
60
60
``` shell
61
- kubectl get pods --all-namespaces -o jsonpath=" {..image}" | \
61
+ kubectl get pods --all-namespaces -o jsonpath=" {.items[*].spec.containers[*] .image}" | \
62
62
tr -s ' [[:space:]]' ' \n' | \
63
63
sort | \
64
64
uniq -c
@@ -132,7 +132,7 @@ following matches only Pods with labels matching `app=nginx`.
132
132
要获取匹配特定标签的 Pod,请使用 -l 参数。以下匹配仅与标签 ` app=nginx ` 相符的 Pod。
133
133
134
134
``` shell
135
- kubectl get pods --all-namespaces -o=jsonpath=" {..image}" -l app=nginx
135
+ kubectl get pods --all-namespaces -o=jsonpath=" {.items[*].spec.containers[*] .image}" -l app=nginx
136
136
```
137
137
138
138
<!--
@@ -146,7 +146,7 @@ following matches only Pods in the `kube-system` namespace.
146
146
要获取匹配特定命名空间的 Pod,请使用 namespace 参数。以下仅匹配 ` kube-system ` 命名空间下的 Pod。
147
147
148
148
``` shell
149
- kubectl get pods --namespace kube-system -o jsonpath=" {..image}"
149
+ kubectl get pods --namespace kube-system -o jsonpath=" {.items[*].spec.containers[*] .image}"
150
150
```
151
151
152
152
<!--
0 commit comments