From 20fe9069549178de4fff13872433454a14e09ab2 Mon Sep 17 00:00:00 2001 From: windsonsea Date: Wed, 18 Sep 2024 17:54:42 +0800 Subject: [PATCH] [zh] Sync a task: debug-cluster/crictl.md --- .../docs/tasks/debug/debug-cluster/crictl.md | 198 +----------------- 1 file changed, 2 insertions(+), 196 deletions(-) diff --git a/content/zh-cn/docs/tasks/debug/debug-cluster/crictl.md b/content/zh-cn/docs/tasks/debug/debug-cluster/crictl.md index fda88d472c..a3e9fe4c85 100644 --- a/content/zh-cn/docs/tasks/debug/debug-cluster/crictl.md +++ b/content/zh-cn/docs/tasks/debug/debug-cluster/crictl.md @@ -126,16 +126,7 @@ The following examples show some `crictl` commands and example output. --> ## crictl 命令示例 {#example-crictl-commands} -{{< warning >}} - -如果使用 `crictl` 在正在运行的 Kubernetes 集群上创建 Pod 沙盒或容器, -kubelet 最终将删除它们。 -`crictl` 不是一个通用的工作流工具,而是一个对调试有用的工具。 -{{< /warning >}} +以下示例展示了一些 `crictl` 命令及其示例输出。 输出类似于这样: -```none +``` 10.240.0.96 - - [06/Jun/2018:02:45:51 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0" "-" ``` - -### 运行 Pod 沙盒 {#run-a-pod-sandbox} - -用 `crictl` 运行 Pod 沙盒对容器运行时排错很有帮助。 -在运行的 Kubernetes 集群中,沙盒会随机地被 kubelet 停止和删除。 - - -1. 编写下面的 JSON 文件: - - ```json - { - "metadata": { - "name": "nginx-sandbox", - "namespace": "default", - "attempt": 1, - "uid": "hdishd83djaidwnduwk28bcsb" - }, - "log_directory": "/tmp", - "linux": { - } - } - ``` - - -2. 使用 `crictl runp` 命令应用 JSON 文件并运行沙盒。 - - ```shell - crictl runp pod-config.json - ``` - - - 返回了沙盒的 ID。 - - -### 创建容器 {#create-a-container} - -用 `crictl` 创建容器对容器运行时排错很有帮助。 -在运行的 Kubernetes 集群中,容器最终将被 kubelet 停止和删除。 - - -1. 拉取 busybox 镜像 - - ```shell - crictl pull busybox - ``` - ```none - Image is up to date for busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47 - ``` - - -2. 创建 Pod 和容器的配置: - - - **Pod 配置**: - - ```json - { - "metadata": { - "name": "busybox-sandbox", - "namespace": "default", - "attempt": 1, - "uid": "aewi4aeThua7ooShohbo1phoj" - }, - "log_directory": "/tmp", - "linux": { - } - } - ``` - - - **容器配置**: - - ```json - { - "metadata": { - "name": "busybox" - }, - "image":{ - "image": "busybox" - }, - "command": [ - "top" - ], - "log_path":"busybox.log", - "linux": { - } - } - ``` - - -3. 创建容器,传递先前创建的 Pod 的 ID、容器配置文件和 Pod 配置文件。返回容器的 ID。 - - ```bash - crictl create f84dd361f8dc51518ed291fbadd6db537b0496536c1d2d6c05ff943ce8c9a54f container-config.json pod-config.json - ``` - - -4. 查询所有容器并确认新创建的容器状态为 `Created`。 - - ```bash - crictl ps -a - ``` - - 输出类似于这样: - - ```none - CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT - 3e025dd50a72d busybox 32 seconds ago Created busybox 0 - ``` - - -### 启动容器 {#start-a-container} - -要启动容器,要将容器 ID 传给 `crictl start`: - -```shell -crictl start 3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60 -``` - - -输出类似于这样: - -``` -3e025dd50a72d956c4f14881fbb5b1080c9275674e95fb67f965f6478a957d60 -``` - - -确认容器的状态为 `Running`。 - -```shell -crictl ps -``` - - -输出类似于这样: - -```none -CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT -3e025dd50a72d busybox About a minute ago Running busybox 0 -``` ## {{% heading "whatsnext" %}}