[zh] Tidy up and fix links in tasks section (8/10)
This commit is contained in:
+16
-34
@@ -5,11 +5,9 @@ weight: 100
|
||||
---
|
||||
|
||||
<!--
|
||||
---
|
||||
title: List All Container Images Running in a Cluster
|
||||
content_type: task
|
||||
weight: 100
|
||||
---
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
@@ -18,17 +16,12 @@ weight: 100
|
||||
This page shows how to use kubectl to list all of the Container images
|
||||
for Pods running in a cluster.
|
||||
-->
|
||||
本文展示如何使用 kubectl 来列出集群中所有运行 pod 的容器的镜像
|
||||
|
||||
|
||||
本文展示如何使用 kubectl 来列出集群中所有运行 Pod 的容器的镜像
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
<!--
|
||||
@@ -36,7 +29,7 @@ In this exercise you will use kubectl to fetch all of the Pods
|
||||
running in a cluster, and format the output to pull out the list
|
||||
of Containers for each.
|
||||
-->
|
||||
在本练习中,您将使用 kubectl 来获取集群中运行的所有 Pod,并格式化输出来提取每个 pod 中的容器列表。
|
||||
在本练习中,你将使用 kubectl 来获取集群中运行的所有 Pod,并格式化输出来提取每个 Pod 中的容器列表。
|
||||
|
||||
<!--
|
||||
## List all Containers in all namespaces
|
||||
@@ -57,13 +50,14 @@ of Containers for each.
|
||||
- 使用 `kubectl get pods --all-namespaces` 获取所有命名空间下的所有 Pod
|
||||
- 使用 `-o jsonpath={..image}` 来格式化输出,以仅包含容器镜像名称。
|
||||
这将以递归方式从返回的 json 中解析出 `image` 字段。
|
||||
- 参阅 [jsonpath reference](/docs/user-guide/jsonpath/) 来获取更多关于如何使用 jsonpath 的信息。
|
||||
- 参阅 [jsonpath 说明](/zh/docs/reference/kubectl/jsonpath/)
|
||||
获取更多关于如何使用 jsonpath 的信息。
|
||||
- 使用标准化工具来格式化输出:`tr`, `sort`, `uniq`
|
||||
- 使用 `tr` 以用换行符替换空格
|
||||
- 使用 `sort` 来对结果进行排序
|
||||
- 使用 `uniq` 来聚合镜像计数
|
||||
|
||||
```sh
|
||||
```shell
|
||||
kubectl get pods --all-namespaces -o jsonpath="{..image}" |\
|
||||
tr -s '[[:space:]]' '\n' |\
|
||||
sort |\
|
||||
@@ -83,7 +77,7 @@ e.g. many fields are called `name` within a given item:
|
||||
|
||||
作为替代方案,可以使用 Pod 的镜像字段的绝对路径。这确保即使字段名称重复的情况下也能检索到正确的字段,例如,特定项目中的许多字段都称为 `name`:
|
||||
|
||||
```sh
|
||||
```shell
|
||||
kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}"
|
||||
```
|
||||
|
||||
@@ -102,13 +96,14 @@ jsonpath 解释如下:
|
||||
- `.containers[*]`: 对于每个容器
|
||||
- `.image`: 获取镜像
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
When fetching a single Pod by name, e.g. `kubectl get pod nginx`,
|
||||
the `.items[*]` portion of the path should be omitted because a single
|
||||
Pod is returned instead of a list of items.
|
||||
-->
|
||||
**注意:** 按名字获取单个 Pod 时,例如 `kubectl get pod nginx`,路径的 `.items[*]` 部分应该省略,因为返回的是一个 Pod 而不是一个项目列表。
|
||||
{{< note >}}
|
||||
按名字获取单个 Pod 时,例如 `kubectl get pod nginx`,路径的 `.items[*]` 部分应该省略,
|
||||
因为返回的是一个 Pod 而不是一个项目列表。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
@@ -121,7 +116,7 @@ iterate over elements individually.
|
||||
|
||||
可以使用 `range` 操作进一步控制格式化,以单独操作每个元素。
|
||||
|
||||
```sh
|
||||
```shell
|
||||
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\
|
||||
sort
|
||||
```
|
||||
@@ -132,11 +127,11 @@ sort
|
||||
To target only Pods matching a specific label, use the -l flag. The
|
||||
following matches only Pods with labels matching `app=nginx`.
|
||||
-->
|
||||
## 列出以 label 过滤后的 Pod 的所有容器
|
||||
## 列出以标签过滤后的 Pod 的所有容器
|
||||
|
||||
要获取匹配特定标签的 Pod,请使用 -l 参数。以下匹配仅与标签 `app=nginx` 相符的 Pod。
|
||||
|
||||
```sh
|
||||
```shell
|
||||
kubectl get pods --all-namespaces -o=jsonpath="{..image}" -l app=nginx
|
||||
```
|
||||
|
||||
@@ -150,7 +145,7 @@ following matches only Pods in the `kube-system` namespace.
|
||||
|
||||
要获取匹配特定命名空间的 Pod,请使用 namespace 参数。以下仅匹配 `kube-system` 命名空间下的 Pod。
|
||||
|
||||
```sh
|
||||
```shell
|
||||
kubectl get pods --namespace kube-system -o jsonpath="{..image}"
|
||||
```
|
||||
|
||||
@@ -164,33 +159,20 @@ for formatting the output:
|
||||
|
||||
作为 jsonpath 的替代,Kubectl 支持使用 [go-templates](https://golang.org/pkg/text/template/) 来格式化输出:
|
||||
|
||||
|
||||
```sh
|
||||
```shell
|
||||
kubectl get pods --all-namespaces -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}"
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- discussion -->
|
||||
|
||||
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
||||
<!--
|
||||
### Reference
|
||||
|
||||
* [Jsonpath](/docs/user-guide/jsonpath/) reference guide
|
||||
* [Jsonpath](/docs/reference/kubectl/jsonpath/) reference guide
|
||||
* [Go template](https://golang.org/pkg/text/template/) reference guide
|
||||
-->
|
||||
### 参考
|
||||
|
||||
* [Jsonpath](/docs/user-guide/jsonpath/) 参考指南
|
||||
* [Jsonpath](/zh/docs/reference/kubectl/jsonpath/) 参考指南
|
||||
* [Go template](https://golang.org/pkg/text/template/) 参考指南
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user