Translated message

A translation of this page exists in English.

如何通过 SSH 访问节点来在 OpenShift 4 中 OpenShift 4 中生成 sos 报告?

Solution Verified - Updated -

Environment

  • Red Hat OpenShift Container Platform (RHOCP)
    • 4
  • Red Hat Enterprise Linux CoreOS (RHCOS)
    • 4

Issue

  • 如何在 OCP 4 中的 Red Hat Enterprise Linux CoreOS 中生成 sos 报告
  • 如何为 Red Hat OpenShift 4 节点生成 sos 报告
  • 使用 rhel7/support-tools 镜像生成 sos 报告 失败,并显示回溯信息。

    [root@ip-1-1-1-1 ~]# podman run -it registry.access.redhat.com/rhel7/support-tools /usr/bin/bash

    bash-4.2# sosreport
    Traceback (most recent call last):
    File "/usr/sbin/sosreport", line 19, in <module>
    main(sys.argv[1:])
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1498, in main
    sos = SoSReport(args)
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 360, in __init__
    self.policy = sos.policies.load(sysroot=self.opts.sysroot)
    File "/usr/lib/python2.7/site-packages/sos/policies/__init__.py", line 44, in load
    cache['policy'] = policy(sysroot=sysroot)
    File "/usr/lib/python2.7/site-packages/sos/policies/redhat.py", line 258, in __init__
    super(RHELPolicy, self).__init__(sysroot=sysroot)
    File "/usr/lib/python2.7/site-packages/sos/policies/redhat.py", line 58, in __init__
    sysroot = self._container_init()
    File "/usr/lib/python2.7/site-packages/sos/policies/redhat.py", line 153, in _container_init
    host_tmp_dir = os.path.abspath(self._host_sysroot + self._tmp_dir)
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Resolution

重要备注:根据设计,OpenShift 4 集群本身是不可变的,它依赖于 Operator 来应用集群更改。这表示,不建议通过 SSH 直接访问底层节点。如果直接进行了访问,节点还会被标记为 accessed 污点。
因此,在可能的情况下,在 oc 命令行中直接创建一个 debug pod 来生成 sosreport,而不是使用 SSH 来生成 sosreport。请参阅 如何在没有 SSH 的情况下,在 OpenShift4 节点中生成 sosreport

只有在无法实现在没有 SSH 的情况下生成 sos 报告 时, 才使用 SSH 直接连接到要生成 sos 报告的 OpenShift Container Platform 4.x 节点,并成为 root 来生成 sos 报告。

$ ssh core@[NODE] # ssh with core user to the NODE using ssh key specified in install-config.yaml
[core@node ~]$ sudo -i

注: 在断开连接的环境中,需要对 registry.redhat.io/rhel8/support-tools 在本地进行镜像。如果镜像已可用于节点,请在使用 registry URL 和自定义 registry 中的镜像名称运行 toolbox 前,在节点上创建一个 /root/.toolboxrc 文件,如下所示:

[root@node ~]# vi /root/.toolboxrc
REGISTRY=private-registry.example.com:5000
IMAGE=rhel8/support-tools

运行 toolbox 命令:

[root@node ~]# toolbox 
Spawning a container 'toolbox-root' with image 'registry.redhat.io/rhel8/support-tools'
Detected RUN label in the container image. Using that as the default...
Command: /proc/self/exe run -it --name toolbox-root --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=toolbox-root -e IMAGE=registry.redhat.io/rhel8/support-tools:latest -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host registry.redhat.io/rhel8/support-tools:latest

执行 sos report 命令:

[root@node ~]# sos report -k crio.all=on -k crio.logs=on  -k podman.all=on -k podman.logs=on

备注:如果有任何插件超时,或者没有收集所有信息,可能需要添加参数 --plugin-timeout=600 来提高插件超时。

这将在容器的 /host/var/tmp 目录中生成 sos 报告(映射到主机的 /var/tmp/)。如需了解将生成的 sosreport 附加到支持问题单的不同方法,请参阅可以使用哪些选项来于复制/共享生成的 sosreport

创建 sos 报告后,运行 exit 从容器的 bash 会话退出到节点:

[root@node ~]# exit
[root@node ~]#

Root Cause

toolbox 命令运行 podman container runlabel run registry.redhat.io/rhel8/support-tools,这是 RHEL Atomic Host 中 atomic run registry.redhat.io/rhel7/support-tools 的替换。

Diagnostic Steps

如果 toolbox 没有如预期启动 debug 容器,请检查用户创建的 $HOME/.toolboxrc 文件,该文件应该会覆盖 REGISTRYIMAGETOOLBOX_NAME 选项的默认值。在断开连接的环境中,需要创建该文件以引用已保存在本地环境中的镜像。

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments