×

关于 must-gather 工具

`oc adm must-gather` CLI 命令会收集集群中用于调试问题最可能需要的信息,包括:

  • 资源定义

  • 服务日志

默认情况下,`oc adm must-gather` 命令使用默认插件镜像并写入 `./must-gather.local`。

或者,您可以通过使用以下部分中描述的适当参数运行该命令来收集特定信息。

  • 要收集与一个或多个特定功能相关的数据,请使用带有镜像的 `--image` 参数,如以下部分所列。

    例如:

    $ oc adm must-gather \
      --image=registry.redhat.io/container-native-virtualization/cnv-must-gather-rhel9:v4.17.3
  • 要收集审计日志,请使用 `-- /usr/bin/gather_audit_logs` 参数,如以下部分所述。

    例如:

    $ oc adm must-gather -- /usr/bin/gather_audit_logs

    为减少文件大小,审计日志不会作为默认信息集的一部分收集。

运行 `oc adm must-gather` 时,会在集群上的新项目中创建一个具有随机名称的新 Pod。数据在该 Pod 上收集,并保存在当前工作目录中以 `must-gather.local` 开头的新的目录中。

例如:

NAMESPACE                      NAME                 READY   STATUS      RESTARTS      AGE
...
openshift-must-gather-5drcj    must-gather-bklx4    2/2     Running     0             72s
openshift-must-gather-5drcj    must-gather-s8sdh    2/2     Running     0             72s
...

或者,您可以使用 `--run-namespace` 选项在特定命名空间中运行 `oc adm must-gather` 命令。

例如:

$ oc adm must-gather --run-namespace <namespace> \
  --image=registry.redhat.io/container-native-virtualization/cnv-must-gather-rhel9:v4.17.3

为 Red Hat 支持收集有关集群的数据

您可以使用 `oc adm must-gather` CLI 命令收集有关集群的调试信息。

前提条件
  • 您具有 `cluster-admin` 角色的用户访问权限。

    在 OpenShift Dedicated 部署中,不使用客户云订阅 (CCS) 模型的客户无法使用 `oc adm must-gather` 命令,因为它需要 `cluster-admin` 权限。

  • 已安装 OpenShift CLI (`oc`)。

步骤
  1. 导航到要存储 `must-gather` 数据的目录。

  2. 运行 `oc adm must-gather` 命令

    $ oc adm must-gather

    因为此命令默认选择随机的控制平面节点,所以 Pod 可能被调度到处于 `NotReady` 和 `SchedulingDisabled` 状态的控制平面节点。

    1. 如果此命令失败,例如,如果无法在集群上调度 Pod,则使用 `oc adm inspect` 命令收集特定资源的信息。

      联系 Red Hat 支持以获取建议收集的资源。

  3. 从刚刚在您的工作目录中创建的 `must-gather` 目录创建一个压缩文件。例如,在使用 Linux 操作系统的计算机上,运行以下命令:

    $ tar cvaf must-gather.tar.gz must-gather.local.5421342344627712289/ (1)
    1 请务必将 `must-gather-local.5421342344627712289/` 替换为实际的目录名称。
  4. 将压缩文件附加到 Red Hat 客户门户网站客户支持页面上的支持案例。

必须收集的标志

下表列出的标志可用于oc adm must-gather命令。

表 1. oc adm must-gather 的 OpenShift Dedicated 标志
标志 示例命令 描述

--all-images

oc adm must-gather --all-images=false

使用所有集群中标注有operators.openshift.io/must-gather-image 的 Operator 的默认镜像收集must-gather数据。

--dest-dir

oc adm must-gather --dest-dir='<directory_name>'

设置本地机器上写入收集数据的特定目录。

--host-network

oc adm must-gather --host-network=false

must-gather Pod 作为hostNetwork: true运行。如果特定命令和镜像需要捕获主机级数据,则相关。

--image

oc adm must-gather --image=[<plugin_image>]

指定要运行的must-gather插件镜像。如果未指定,则使用 OpenShift Dedicated 的默认must-gather镜像。

--image-stream

oc adm must-gather --image-stream=[<image_stream>]

使用包含要运行的must-gather插件镜像的命名空间或 name:tag 值指定一个`<image_stream>`。

--node-name

oc adm must-gather --node-name='<node>'

设置要使用的特定节点。如果未指定,则默认使用随机主节点。

--node-selector

oc adm must-gather --node-selector='<node_selector_name>'

设置要使用的特定节点选择器。仅当指定需要同时在集群节点集上捕获数据的命令和镜像时才相关。

--run-namespace

oc adm must-gather --run-namespace='<namespace>'

must-gather Pod 应该运行的现有特权命名空间。如果未指定,则会生成一个临时命名空间。

--since

oc adm must-gather --since=<time>

仅返回比指定持续时间新的日志。默认为所有日志。鼓励但不要求插件支持此功能。只能使用一个since-timesince

--since-time

oc adm must-gather --since-time='<date_and_time>'

仅返回特定日期和时间(以 (RFC3339) 格式表示)之后的日志。默认为所有日志。鼓励但不要求插件支持此功能。只能使用一个since-timesince

--source-dir

oc adm must-gather --source-dir='/<directory_name>/'

设置 Pod 上复制收集数据的特定目录。

--timeout

oc adm must-gather --timeout='<time>'

收集数据超时前的时长,以秒、分或小时表示,例如 3s、5m 或 2h。指定的时间必须大于零。如果未指定,则默认为 10 分钟。

--volume-percentage

oc adm must-gather --volume-percentage=<percent>

指定可用于must-gather的 Pod 已分配卷的最大百分比。如果超过此限制,must-gather将停止收集,但仍会复制收集的数据。如果未指定,则默认为 30%。

收集关于特定功能的数据

您可以使用带有--image--image-stream参数的oc adm must-gather CLI 命令来收集关于特定功能的调试信息。must-gather工具支持多个镜像,因此您可以通过运行单个命令来收集多个功能的数据。

表 2. 受支持的 must-gather 镜像
镜像 用途

registry.redhat.io/container-native-virtualization/cnv-must-gather-rhel9:v4.17.3

OpenShift Virtualization 的数据收集。

registry.redhat.io/openshift-serverless-1/svls-must-gather-rhel8

OpenShift Serverless 的数据收集。

registry.redhat.io/openshift-service-mesh/istio-must-gather-rhel8:<installed_version_service_mesh>

Red Hat OpenShift Service Mesh 的数据收集。

registry.redhat.io/rhmtc/openshift-migration-must-gather-rhel8:v<installed_version_migration_toolkit>

容器迁移工具包的数据收集。

registry.redhat.io/openshift-logging/cluster-logging-rhel9-operator:v<installed_version_logging>

日志记录的数据收集。

quay.io/netobserv/must-gather

网络可观测性 Operator 的数据收集。

registry.redhat.io/openshift4/ose-csi-driver-shared-resource-mustgather-rhel8

OpenShift 共享资源 CSI 驱动程序的数据收集。

registry.redhat.io/openshift-gitops-1/must-gather-rhel8:v<installed_version_GitOps>

Red Hat OpenShift GitOps 的数据收集。

registry.redhat.io/openshift4/ose-secrets-store-csi-mustgather-rhel8:v<installed_version_secret_store>

Secrets Store CSI Driver Operator 的数据收集。

要确定 OpenShift Dedicated 组件镜像的最新版本,请参阅 Red Hat 客户门户网站上的OpenShift Operator 生命周期网页。

前提条件
  • 您具有 `cluster-admin` 角色的用户访问权限。

  • 已安装 OpenShift CLI (`oc`)。

步骤
  1. 导航到要存储 `must-gather` 数据的目录。

  2. 使用一个或多个--image--image-stream参数运行oc adm must-gather命令。

    • 要收集默认的must-gather数据以及特定功能数据,请添加--image-stream=openshift/must-gather参数。

    例如,以下命令同时收集默认集群数据和 OpenShift Virtualization 的特定信息

    $ oc adm must-gather \
      --image-stream=openshift/must-gather \ (1)
      --image=registry.redhat.io/container-native-virtualization/cnv-must-gather-rhel9:v4.17.3 (2)
    
    1 默认的 OpenShift Dedicated must-gather镜像
    2 OpenShift Virtualization 的 must-gather 镜像

    您可以使用must-gather工具以及其他参数来收集与 OpenShift 日志记录和集群中的集群日志记录 Operator 特别相关的数据。对于 OpenShift 日志记录,请运行以下命令

    $ oc adm must-gather --image=$(oc -n openshift-logging get deployment.apps/cluster-logging-operator \
      -o jsonpath='{.spec.template.spec.containers[?(@.name == "cluster-logging-operator")].image}')
    OpenShift 日志记录的示例must-gather输出
    ├── cluster-logging
    │  ├── clo
    │  │  ├── cluster-logging-operator-74dd5994f-6ttgt
    │  │  ├── clusterlogforwarder_cr
    │  │  ├── cr
    │  │  ├── csv
    │  │  ├── deployment
    │  │  └── logforwarding_cr
    │  ├── collector
    │  │  ├── fluentd-2tr64
    │  ├── curator
    │  │  └── curator-1596028500-zkz4s
    │  ├── eo
    │  │  ├── csv
    │  │  ├── deployment
    │  │  └── elasticsearch-operator-7dc7d97b9d-jb4r4
    │  ├── es
    │  │  ├── cluster-elasticsearch
    │  │  │  ├── aliases
    │  │  │  ├── health
    │  │  │  ├── indices
    │  │  │  ├── latest_documents.json
    │  │  │  ├── nodes
    │  │  │  ├── nodes_stats.json
    │  │  │  └── thread_pool
    │  │  ├── cr
    │  │  ├── elasticsearch-cdm-lp8l38m0-1-794d6dd989-4jxms
    │  │  └── logs
    │  │     ├── elasticsearch-cdm-lp8l38m0-1-794d6dd989-4jxms
    │  ├── install
    │  │  ├── co_logs
    │  │  ├── install_plan
    │  │  ├── olmo_logs
    │  │  └── subscription
    │  └── kibana
    │     ├── cr
    │     ├── kibana-9d69668d4-2rkvz
    ├── cluster-scoped-resources
    │  └── core
    │     ├── nodes
    │     │  ├── ip-10-0-146-180.eu-west-1.compute.internal.yaml
    │     └── persistentvolumes
    │        ├── pvc-0a8d65d9-54aa-4c44-9ecc-33d9381e41c1.yaml
    ├── event-filter.html
    ├── gather-debug.log
    └── namespaces
       ├── openshift-logging
       │  ├── apps
       │  │  ├── daemonsets.yaml
       │  │  ├── deployments.yaml
       │  │  ├── replicasets.yaml
       │  │  └── statefulsets.yaml
       │  ├── batch
       │  │  ├── cronjobs.yaml
       │  │  └── jobs.yaml
       │  ├── core
       │  │  ├── configmaps.yaml
       │  │  ├── endpoints.yaml
       │  │  ├── events
       │  │  │  ├── curator-1596021300-wn2ks.162634ebf0055a94.yaml
       │  │  │  ├── curator.162638330681bee2.yaml
       │  │  │  ├── elasticsearch-delete-app-1596020400-gm6nl.1626341a296c16a1.yaml
       │  │  │  ├── elasticsearch-delete-audit-1596020400-9l9n4.1626341a2af81bbd.yaml
       │  │  │  ├── elasticsearch-delete-infra-1596020400-v98tk.1626341a2d821069.yaml
       │  │  │  ├── elasticsearch-rollover-app-1596020400-cc5vc.1626341a3019b238.yaml
       │  │  │  ├── elasticsearch-rollover-audit-1596020400-s8d5s.1626341a31f7b315.yaml
       │  │  │  ├── elasticsearch-rollover-infra-1596020400-7mgv8.1626341a35ea59ed.yaml
       │  │  ├── events.yaml
       │  │  ├── persistentvolumeclaims.yaml
       │  │  ├── pods.yaml
       │  │  ├── replicationcontrollers.yaml
       │  │  ├── secrets.yaml
       │  │  └── services.yaml
       │  ├── openshift-logging.yaml
       │  ├── pods
       │  │  ├── cluster-logging-operator-74dd5994f-6ttgt
       │  │  │  ├── cluster-logging-operator
       │  │  │  │  └── cluster-logging-operator
       │  │  │  │     └── logs
       │  │  │  │        ├── current.log
       │  │  │  │        ├── previous.insecure.log
       │  │  │  │        └── previous.log
       │  │  │  └── cluster-logging-operator-74dd5994f-6ttgt.yaml
       │  │  ├── cluster-logging-operator-registry-6df49d7d4-mxxff
       │  │  │  ├── cluster-logging-operator-registry
       │  │  │  │  └── cluster-logging-operator-registry
       │  │  │  │     └── logs
       │  │  │  │        ├── current.log
       │  │  │  │        ├── previous.insecure.log
       │  │  │  │        └── previous.log
       │  │  │  ├── cluster-logging-operator-registry-6df49d7d4-mxxff.yaml
       │  │  │  └── mutate-csv-and-generate-sqlite-db
       │  │  │     └── mutate-csv-and-generate-sqlite-db
       │  │  │        └── logs
       │  │  │           ├── current.log
       │  │  │           ├── previous.insecure.log
       │  │  │           └── previous.log
       │  │  ├── curator-1596028500-zkz4s
       │  │  ├── elasticsearch-cdm-lp8l38m0-1-794d6dd989-4jxms
       │  │  ├── elasticsearch-delete-app-1596030300-bpgcx
       │  │  │  ├── elasticsearch-delete-app-1596030300-bpgcx.yaml
       │  │  │  └── indexmanagement
       │  │  │     └── indexmanagement
       │  │  │        └── logs
       │  │  │           ├── current.log
       │  │  │           ├── previous.insecure.log
       │  │  │           └── previous.log
       │  │  ├── fluentd-2tr64
       │  │  │  ├── fluentd
       │  │  │  │  └── fluentd
       │  │  │  │     └── logs
       │  │  │  │        ├── current.log
       │  │  │  │        ├── previous.insecure.log
       │  │  │  │        └── previous.log
       │  │  │  ├── fluentd-2tr64.yaml
       │  │  │  └── fluentd-init
       │  │  │     └── fluentd-init
       │  │  │        └── logs
       │  │  │           ├── current.log
       │  │  │           ├── previous.insecure.log
       │  │  │           └── previous.log
       │  │  ├── kibana-9d69668d4-2rkvz
       │  │  │  ├── kibana
       │  │  │  │  └── kibana
       │  │  │  │     └── logs
       │  │  │  │        ├── current.log
       │  │  │  │        ├── previous.insecure.log
       │  │  │  │        └── previous.log
       │  │  │  ├── kibana-9d69668d4-2rkvz.yaml
       │  │  │  └── kibana-proxy
       │  │  │     └── kibana-proxy
       │  │  │        └── logs
       │  │  │           ├── current.log
       │  │  │           ├── previous.insecure.log
       │  │  │           └── previous.log
       │  └── route.openshift.io
       │     └── routes.yaml
       └── openshift-operators-redhat
          ├── ...
  3. 使用一个或多个--image--image-stream参数运行oc adm must-gather命令。例如,以下命令同时收集默认集群数据和 KubeVirt 的特定信息

    $ oc adm must-gather \
     --image-stream=openshift/must-gather \ (1)
     --image=quay.io/kubevirt/must-gather (2)
    
    1 默认的 OpenShift Dedicated must-gather镜像
    2 KubeVirt 的 must-gather 镜像
  4. 从刚刚在您的工作目录中创建的 `must-gather` 目录创建一个压缩文件。例如,在使用 Linux 操作系统的计算机上,运行以下命令:

    $ tar cvaf must-gather.tar.gz must-gather.local.5421342344627712289/ (1)
    1 请务必将 `must-gather-local.5421342344627712289/` 替换为实际的目录名称。
  5. 将压缩文件附加到 Red Hat 客户门户网站客户支持页面上的支持案例。

其他资源

收集网络日志

您可以收集集群中所有节点上的网络日志。

步骤
  1. 使用--gather_network_logs运行oc adm must-gather命令

    $ oc adm must-gather -- gather_network_logs

    默认情况下,must-gather工具会从集群中的所有节点收集 OVN nbdbsbdb数据库。添加--gather_network_logs选项以包含包含 OVN nbdb数据库的 OVN-Kubernetes 事务的其他日志。

  2. 从刚刚在您的工作目录中创建的 `must-gather` 目录创建一个压缩文件。例如,在使用 Linux 操作系统的计算机上,运行以下命令:

    $ tar cvaf must-gather.tar.gz must-gather.local.472290403699006248 (1)
    1 must-gather-local.472290403699006248替换为实际的目录名。
  3. 将压缩文件附加到 Red Hat 客户门户网站客户支持页面上的支持案例。

更改 must-gather 存储限制

使用oc adm must-gather命令收集数据时,信息的默认最大存储空间为容器存储容量的 30%。达到 30% 的限制后,容器将被终止,收集过程将停止。已收集的信息将下载到您的本地存储。要再次运行 must-gather 命令,您需要一个具有更大存储容量的容器或调整最大卷百分比。

如果容器达到存储限制,则会生成类似于以下示例的错误消息。

示例输出
Disk usage exceeds the volume percentage of 30% for mounted directory. Exiting...
前提条件
  • 您具有 `cluster-admin` 角色的用户访问权限。

  • 已安装 OpenShift CLI (`oc`)。

步骤
  • 使用volume-percentage标志运行oc adm must-gather命令。新值不能超过 100。

    $ oc adm must-gather --volume-percentage <storage_percentage>

获取您的集群 ID

向 Red Hat 支持提供信息时,提供集群的唯一标识符非常有用。您可以使用 OpenShift Dedicated Web 控制台自动填充集群 ID。您也可以使用 Web 控制台或 OpenShift CLI (oc) 手动获取集群 ID。

前提条件
  • 您拥有集群的访问权限,并具有dedicated-admin角色。

  • 您可以访问 Web 控制台或已安装的 OpenShift CLI(oc)。

步骤
  • 使用OpenShift 集群管理器手动获取您的集群 ID

    1. 导航到**集群列表**。

    2. 点击您需要为其打开支持案例的集群名称。

    3. 在**概述**选项卡的**详细信息**部分的**集群 ID**字段中找到该值。

  • 使用 Web 控制台打开支持案例并自动填充您的集群 ID

    1. 从工具栏中,导航到**(?) 帮助**,然后从列表中选择**分享反馈**。

    2. 在**告诉我们您的体验**窗口中点击**打开支持案例**。

  • 使用 Web 控制台手动获取您的集群 ID

    1. 导航到**主页** → **概述**。

    2. 该值可在**详细信息**部分的**集群 ID**字段中找到。

  • 要使用 OpenShift CLI(oc)获取您的集群 ID,请运行以下命令

    $ oc get clusterversion -o jsonpath='{.items[].spec.clusterID}{"\n"}'

查询集群节点日志

您可以收集各个集群节点上的journald单元日志和/var/log中的其他日志。

前提条件
  • 您具有 `cluster-admin` 角色的用户访问权限。

    在 OpenShift Dedicated 部署中,不使用客户云订阅 (CCS) 模型的客户无法使用oc adm node-logs命令,因为它需要cluster-admin权限。

  • 您已安装 OpenShift CLI(oc)。

步骤
  1. 查询 OpenShift Dedicated 集群节点上的kubelet journald单元日志。以下示例仅查询控制平面节点

    $ oc adm node-logs --role=master -u kubelet  (1)
    1 根据需要替换kubelet以查询其他单元日志。
  2. 收集集群节点上/var/log/下特定子目录中的日志。

    1. 检索/var/log/子目录中包含的日志列表。以下示例列出所有控制平面节点上/var/log/openshift-apiserver/中的文件

      $ oc adm node-logs --role=master --path=openshift-apiserver
    2. 检查/var/log/子目录中的特定日志。以下示例输出所有控制平面节点上的/var/log/openshift-apiserver/audit.log内容

      $ oc adm node-logs --role=master --path=openshift-apiserver/audit.log

网络跟踪方法

收集网络跟踪(以数据包捕获记录的形式)可以帮助 Red Hat 支持团队排除网络问题。

OpenShift Dedicated 支持两种执行网络跟踪的方法。查看下表并选择满足您需求的方法。

表 3. 支持的网络跟踪收集方法
方法 优点和功能

收集主机网络跟踪

您可以在一个或多个节点上同时执行指定持续时间的包捕获。满足指定持续时间后,包捕获文件将从节点传输到客户端机器。

您可以排查为什么特定操作会触发网络通信问题。运行包捕获,执行触发问题的操作,然后使用日志诊断问题。

从 OpenShift Dedicated 节点或容器收集网络跟踪

您在一个节点或一个容器上执行包捕获。您交互式地运行tcpdump命令,因此您可以控制包捕获的持续时间。

您可以手动启动包捕获,触发网络通信问题,然后手动停止包捕获。

此方法使用cat命令和 shell 重定向将包捕获数据从节点或容器复制到客户端机器。

收集主机网络跟踪

有时,通过跟踪网络通信和同时捕获多个节点上的数据包来简化网络相关问题的故障排除。

您可以结合使用oc adm must-gather命令和registry.redhat.io/openshift4/network-tools-rhel8容器镜像来从节点收集包捕获。分析包捕获可以帮助您排查网络通信问题。

oc adm must-gather命令用于在特定节点上的 Pod 中运行tcpdump命令。tcpdump命令记录 Pod 中的包捕获。当tcpdump命令退出时,oc adm must-gather命令会将包含包捕获的文件从 Pod 传输到您的客户端机器。

以下步骤中的示例命令演示了使用tcpdump命令执行包捕获。但是,您可以在--image参数中指定的容器镜像中运行任何命令,以同时从多个节点收集故障排除信息。

前提条件
  • 您已以具有cluster-admin角色的用户身份登录到 OpenShift Dedicated。

    在 OpenShift Dedicated 部署中,不使用客户云订阅 (CCS) 模型的客户无法使用 `oc adm must-gather` 命令,因为它需要 `cluster-admin` 权限。

  • 您已安装 OpenShift CLI(oc)。

步骤
  1. 通过运行以下命令从主机网络上的一些节点运行包捕获

    $ oc adm must-gather \
        --dest-dir /tmp/captures \  (1)
        --source-dir '/tmp/tcpdump/' \  (2)
        --image registry.redhat.io/openshift4/network-tools-rhel8:latest \  (3)
        --node-selector 'node-role.kubernetes.io/worker' \  (4)
        --host-network=true \  (5)
        --timeout 30s \  (6)
        -- \
        tcpdump -i any \  (7)
        -w /tmp/tcpdump/%Y-%m-%dT%H:%M:%S.pcap -W 1 -G 300
    1 --dest-dir参数指定oc adm must-gather将包捕获存储在客户端机器上相对于/tmp/captures的目录中。您可以指定任何可写目录。
    2 当在oc adm must-gather启动的调试 Pod 中运行tcpdump时,--source-dir参数指定包捕获临时存储在 Pod 上的/tmp/tcpdump目录中。
    3 --image参数指定包含tcpdump命令的容器镜像。
    4 --node-selector参数和示例值指定在工作节点上执行包捕获。或者,您可以改为指定--node-name参数以在一个节点上运行包捕获。如果您同时省略--node-selector--node-name参数,则会在所有节点上执行包捕获。
    5 需要--host-network=true参数,以便在节点的网络接口上执行包捕获。
    6 --timeout参数和值指定调试 Pod 运行 30 秒。如果您没有指定--timeout参数和持续时间,则调试 Pod 将运行 10 分钟。
    7 tcpdump命令的-i any参数指定在所有网络接口上捕获数据包。或者,您可以指定网络接口名称。
  2. 执行操作(例如访问 Web 应用程序),在网络跟踪捕获数据包时触发网络通信问题。

  3. 查看oc adm must-gather从 Pod 传输到客户端机器的包捕获文件

    tmp/captures
    ├── event-filter.html
    ├── ip-10-0-192-217-ec2-internal  (1)
    │   └── registry-redhat-io-openshift4-network-tools-rhel8-sha256-bca...
    │       └── 2022-01-13T19:31:31.pcap
    ├── ip-10-0-201-178-ec2-internal  (1)
    │   └── registry-redhat-io-openshift4-network-tools-rhel8-sha256-bca...
    │       └── 2022-01-13T19:31:30.pcap
    ├── ip-...
    └── timestamp
    1 包捕获存储在标识主机名、容器和文件名文件的目录中。如果您没有指定--node-selector参数,则主机名的目录级别不存在。

从 OpenShift Dedicated 节点或容器收集网络跟踪

在调查潜在的网络相关 OpenShift Dedicated 问题时,Red Hat 支持团队可能会请求来自特定 OpenShift Dedicated 集群节点或特定容器的网络数据包跟踪。在 OpenShift Dedicated 中捕获网络跟踪的推荐方法是通过调试 Pod。

前提条件
  • 您具有 `cluster-admin` 角色的用户访问权限。

    在 OpenShift Dedicated 部署中,不使用客户云订阅 (CCS) 模型的客户无法使用oc debug命令,因为它需要cluster-admin权限。

  • 您已安装 OpenShift CLI(oc)。

  • 您有一个现有的 Red Hat 支持案例 ID。

步骤
  1. 获取集群节点列表

    $ oc get nodes
  2. 进入目标节点的调试会话。此步骤会实例化一个名为<node_name>-debug的调试 Pod。

    $ oc debug node/my-cluster-node
  3. /host设置为调试 shell 中的根目录。调试 Pod 将宿主机根文件系统挂载到 Pod 内的/host目录下。通过将根目录更改为/host,您可以运行宿主机可执行路径中包含的二进制文件。

    # chroot /host
  4. chroot环境控制台中,获取节点的接口名称。

    # ip ad
  5. 启动一个toolbox容器,其中包含运行sosreport所需的二进制文件和插件。

    # toolbox

    如果已存在正在运行的toolbox Pod,则toolbox命令会输出'toolbox-' already exists. Trying to start…​。为避免tcpdump问题,请使用podman rm toolbox-删除正在运行的 toolbox 容器,然后启动一个新的 toolbox 容器。

  6. 在集群节点上启动tcpdump会话并将输出重定向到捕获文件。此示例使用ens5作为接口名称。

    $ tcpdump -nn -s 0 -i ens5 -w /host/var/tmp/my-cluster-node_$(date +%d_%m_%Y-%H_%M_%S-%Z).pcap  (1)
    1 tcpdump捕获文件的路径位于chroot环境之外,因为 toolbox 容器将宿主机根目录挂载到/host
  7. 如果需要对节点上的特定容器进行tcpdump捕获,请按照以下步骤操作。

    1. 确定目标容器 ID。由于 toolbox 容器将宿主机根目录挂载到/host,因此此步骤中chroot host命令位于crictl命令之前。

      # chroot /host crictl ps
    2. 确定容器的进程 ID。在此示例中,容器 ID 为a7fe32346b120

      # chroot /host crictl inspect --output yaml a7fe32346b120 | grep 'pid' | awk '{print $2}'
    3. 在容器上启动tcpdump会话并将输出重定向到捕获文件。此示例使用49628作为容器的进程 ID,并使用ens5作为接口名称。nsenter命令进入目标进程的命名空间并在其命名空间中运行命令。因为此示例中的目标进程是容器的进程 ID,所以tcpdump命令在宿主机上从容器的命名空间运行。

      # nsenter -n -t 49628 -- tcpdump -nn -i ens5 -w /host/var/tmp/my-cluster-node-my-container_$(date +%d_%m_%Y-%H_%M_%S-%Z).pcap  (1)
      1 tcpdump捕获文件的路径位于chroot环境之外,因为 toolbox 容器将宿主机根目录挂载到/host
  8. 使用以下方法之一,将tcpdump捕获文件提供给 Red Hat 支持团队进行分析。

    • 直接从 OpenShift Dedicated 集群将文件上传到现有的 Red Hat 支持案例。

      1. 在 toolbox 容器内,运行redhat-support-tool将文件直接附加到现有的 Red Hat 支持案例。此示例使用支持案例 ID 01234567

        # redhat-support-tool addattachment -c 01234567 /host/var/tmp/my-tcpdump-capture-file.pcap (1)
        1 toolbox 容器将宿主机根目录挂载到/host。通过redhat-support-tool命令指定要上传的文件时,请参考从 toolbox 容器根目录开始的绝对路径,包括/host/
    • 将文件上传到现有的 Red Hat 支持案例。

      1. 通过运行oc debug node/<node_name>命令连接sosreport存档并将输出重定向到文件。此命令假设您已退出之前的oc debug会话。

        $ oc debug node/my-cluster-node -- bash -c 'cat /host/var/tmp/my-tcpdump-capture-file.pcap' > /tmp/my-tcpdump-capture-file.pcap (1)
        1 调试容器将宿主机根目录挂载到/host。指定要连接的目标文件时,请参考从调试容器根目录开始的绝对路径,包括/host
      2. 在 Red Hat 客户门户网站的客户支持页面中导航到现有的支持案例。

      3. 选择附加文件并按照提示上传文件。

向 Red Hat 支持团队提供诊断数据

在调查 OpenShift Dedicated 问题时,Red Hat 支持团队可能会要求您将诊断数据上传到支持案例。文件可以通过 Red Hat 客户门户网站上传到支持案例,也可以直接通过 OpenShift Dedicated 集群使用redhat-support-tool命令上传。

前提条件
  • 您具有 `cluster-admin` 角色的用户访问权限。

    在 OpenShift Dedicated 部署中,不使用客户云订阅 (CCS) 模型的客户无法使用oc debug命令,因为它需要cluster-admin权限。

  • 您已安装 OpenShift CLI(oc)。

  • 您有一个现有的 Red Hat 支持案例 ID。

步骤
  • 通过 Red Hat 客户门户网站将诊断数据上传到现有的 Red Hat 支持案例。

    1. 使用oc debug node/<node_name>命令连接 OpenShift Dedicated 节点上的诊断文件并将输出重定向到文件。以下示例将/host/var/tmp/my-diagnostic-data.tar.gz从调试容器复制到/var/tmp/my-diagnostic-data.tar.gz

      $ oc debug node/my-cluster-node -- bash -c 'cat /host/var/tmp/my-diagnostic-data.tar.gz' > /var/tmp/my-diagnostic-data.tar.gz (1)
      1 调试容器将宿主机根目录挂载到/host。指定要连接的目标文件时,请参考从调试容器根目录开始的绝对路径,包括/host
    2. 在 Red Hat 客户门户网站的客户支持页面中导航到现有的支持案例。

    3. 选择附加文件并按照提示上传文件。

关于toolbox

toolbox是一个在 Red Hat Enterprise Linux CoreOS (RHCOS) 系统上启动容器的工具。该工具主要用于启动一个包含运行sosreportredhat-support-tool等命令所需的二进制文件和插件的容器。

toolbox容器的主要目的是收集诊断信息并将其提供给 Red Hat 支持团队。但是,如果需要其他诊断工具,您可以添加 RPM 包或运行作为标准支持工具镜像的替代方案的镜像。

toolbox容器安装软件包

默认情况下,运行toolbox命令会使用registry.redhat.io/rhel9/support-tools:latest镜像启动一个容器。此镜像包含最常用的支持工具。如果您需要收集需要镜像中未包含的支持工具的节点特定数据,则可以安装其他软件包。

前提条件
  • 您已使用oc debug node/<node_name>命令访问了节点。

  • 您可以以具有 root 权限的用户身份访问您的系统。

步骤
  1. /host设置为调试 shell 中的根目录。调试 Pod 将宿主机根文件系统挂载到 Pod 内的/host目录下。通过将根目录更改为/host,您可以运行宿主机可执行路径中包含的二进制文件。

    # chroot /host
  2. 启动 toolbox 容器

    # toolbox
  3. 安装其他软件包,例如wget

    # dnf install -y <package_name>

使用toolbox启动替代镜像

默认情况下,运行toolbox命令会使用registry.redhat.io/rhel9/support-tools:latest镜像启动一个容器。

您可以通过创建.toolboxrc文件并指定要运行的镜像来启动替代镜像。但是,在 OpenShift Dedicated 上不支持运行旧版本的support-tools镜像,例如registry.redhat.io/rhel8/support-tools:latest

前提条件
  • 您已使用oc debug node/<node_name>命令访问了节点。

  • 您可以以具有 root 权限的用户身份访问您的系统。

步骤
  1. /host设置为调试 shell 中的根目录。调试 Pod 将宿主机根文件系统挂载到 Pod 内的/host目录下。通过将根目录更改为/host,您可以运行宿主机可执行路径中包含的二进制文件。

    # chroot /host
  2. 可选:如果您需要使用替代镜像而不是默认镜像,请在 root 用户 ID 的主目录中创建一个.toolboxrc文件,并指定镜像元数据。

    REGISTRY=quay.io             (1)
    IMAGE=fedora/fedora:latest   (2)
    TOOLBOX_NAME=toolbox-fedora-latest  (3)
    1 可选:指定替代容器注册表。
    2 指定要启动的替代镜像。
    3 可选:为 toolbox 容器指定替代名称。
  3. 通过输入以下命令启动 toolbox 容器

    # toolbox

    如果已存在正在运行的toolbox Pod,则toolbox命令会输出'toolbox-' already exists. Trying to start…​。为避免sosreport插件出现问题,请使用podman rm toolbox-删除正在运行的 toolbox 容器,然后启动一个新的 toolbox 容器。