11.4. 订阅集群节点的 Redfish BMC 裸机事件

作为集群管理员,您可以通过为节点创建一个 BMCEventSubscription 自定义资源(CR)、为事件创建一个 HardwareEvent CR 并为 BMC 创建一个 Secret CR,订阅在集群的节点上生成的 Redfish BMC 事件。

11.4.1. 订阅裸机事件

您可以配置基板管理控制器(BMC)将裸机事件发送到 OpenShift Container Platform 集群中运行的订阅应用程序。Redfish 裸机事件示例包括增加设备温度或删除设备。您可以使用 REST API 将应用程序订阅到裸机事件。

重要

您只能为支持 Redfish 的物理硬件创建一个 BMCEventSubscription 自定义资源(CR),并将厂商接口设置为 redfishidrac-redfish

注意

使用 BMCEventSubscription CR 订阅预定义的 Redfish 事件。Redfish 标准不提供创建特定警报和阈值的选项。例如,当机箱的温度超过 40Gb 摄氏度时收到警报事件,您必须根据供应商的建议手动配置事件。

执行以下步骤使用 BMCEventSubscription CR 为节点订阅裸机事件。

先决条件

  • 安装 OpenShift CLI(oc)。
  • 以具有 cluster-admin 特权的用户身份登录。
  • 获取 BMC 的用户名和密码。
  • 使用集群中启用了 Redfish 的 Baseboard Management Controller(BMC)部署裸机节点,并在 BMC 上启用 Redfish 事件。

    注意

    在特定硬件上启用 Redfish 事件超出了此信息的范围。有关为特定硬件启用 Redfish 事件的更多信息,请参阅 BMC 厂商文档。

流程

  1. 通过运行以下 curl 命令确认节点硬件启用了 Redfish EventService

    curl https://<bmc_ip_address>/redfish/v1/EventService --insecure -H 'Content-Type: application/json' -u "<bmc_username>:<password>"

    其中:

    bmc_ip_address
    是生成 Redfish 事件的 BMC 的 IP 地址。

    输出示例

    {
       "@odata.context": "/redfish/v1/$metadata#EventService.EventService",
       "@odata.id": "/redfish/v1/EventService",
       "@odata.type": "#EventService.v1_0_2.EventService",
       "Actions": {
          "#EventService.SubmitTestEvent": {
             "EventType@Redfish.AllowableValues": ["StatusChange", "ResourceUpdated", "ResourceAdded", "ResourceRemoved", "Alert"],
             "target": "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent"
          }
       },
       "DeliveryRetryAttempts": 3,
       "DeliveryRetryIntervalSeconds": 30,
       "Description": "Event Service represents the properties for the service",
       "EventTypesForSubscription": ["StatusChange", "ResourceUpdated", "ResourceAdded", "ResourceRemoved", "Alert"],
       "EventTypesForSubscription@odata.count": 5,
       "Id": "EventService",
       "Name": "Event Service",
       "ServiceEnabled": true,
       "Status": {
          "Health": "OK",
          "HealthRollup": "OK",
          "State": "Enabled"
       },
       "Subscriptions": {
          "@odata.id": "/redfish/v1/EventService/Subscriptions"
       }
    }

  2. 运行以下命令,获取集群的 Bare Metal 事件中继服务路由:

    $ oc get route -n openshift-bare-metal-events

    输出示例

    NAME             HOST/PORT                                                                                           PATH   SERVICES                 PORT   TERMINATION   WILDCARD
    hw-event-proxy   hw-event-proxy-openshift-bare-metal-events.apps.compute-1.example.com          hw-event-proxy-service   9087   edge          None

  3. 创建一个 BMCEventSubscription 资源来订阅 Redfish 事件:

    1. 将以下 YAML 保存到 bmc_sub.yaml 文件中:

      apiVersion: metal3.io/v1alpha1
      kind: BMCEventSubscription
      metadata:
        name: sub-01
        namespace: openshift-machine-api
      spec:
         hostName: <hostname> 1
         destination: <proxy_service_url> 2
         context: ''
      1
      指定生成 Redfish 事件的 worker 节点的名称或 UUID。
      2
    2. 创建 BMCEventSubscription CR:

      $ oc create -f bmc_sub.yaml
  4. 可选: 要删除 BMC 事件订阅,请运行以下命令:

    $ oc delete -f bmc_sub.yaml
  5. 可选: 要在不创建 BMCEventSubscription CR 的情况下手动创建 Redfish 事件订阅,请运行以下 curl 命令并指定 BMC 用户名和密码。

    $ curl -i -k -X POST -H "Content-Type: application/json"  -d '{"Destination": "https://<proxy_service_url>", "Protocol" : "Redfish", "EventTypes": ["Alert"], "Context": "root"}' -u <bmc_username>:<password> 'https://<bmc_ip_address>/redfish/v1/EventService/Subscriptions' –v

    其中:

    bmc_ip_address
    是生成 Redfish 事件的 BMC 的 IP 地址。

    输出示例

    HTTP/1.1 201 Created
    Server: AMI MegaRAC Redfish Service
    Location: /redfish/v1/EventService/Subscriptions/1
    Allow: GET, POST
    Access-Control-Allow-Origin: *
    Access-Control-Expose-Headers: X-Auth-Token
    Access-Control-Allow-Headers: X-Auth-Token
    Access-Control-Allow-Credentials: true
    Cache-Control: no-cache, must-revalidate
    Link: <http://redfish.dmtf.org/schemas/v1/EventDestination.v1_6_0.json>; rel=describedby
    Link: <http://redfish.dmtf.org/schemas/v1/EventDestination.v1_6_0.json>
    Link: </redfish/v1/EventService/Subscriptions>; path=
    ETag: "1651135676"
    Content-Type: application/json; charset=UTF-8
    OData-Version: 4.0
    Content-Length: 614
    Date: Thu, 28 Apr 2022 08:47:57 GMT

11.4.2. 使用 curl 查询 Redfish 裸机事件订阅

有些硬件供应商限制 Redfish 硬件事件订阅的数量。您可以使用 curl 查询 Redfish 事件订阅的数量。

先决条件

  • 获取 BMC 的用户名和密码。
  • 使用集群中启用了 Redfish 的 Baseboard Management Controller(BMC)部署裸机节点,并在 BMC 上启用 Redfish 硬件事件。

流程

  1. 运行以下 curl 命令,检查 BMC 的当前订阅:

    $ curl --globoff -H "Content-Type: application/json" -k -X GET --user <bmc_username>:<password> https://<bmc_ip_address>/redfish/v1/EventService/Subscriptions

    其中:

    bmc_ip_address
    是生成 Redfish 事件的 BMC 的 IP 地址。

    输出示例

    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 435 100 435 0 0 399 0 0:00:01 0:00:01 --:--:-- 399
    {
      "@odata.context": "/redfish/v1/$metadata#EventDestinationCollection.EventDestinationCollection",
      "@odata.etag": ""
      1651137375 "",
      "@odata.id": "/redfish/v1/EventService/Subscriptions",
      "@odata.type": "#EventDestinationCollection.EventDestinationCollection",
      "Description": "Collection for Event Subscriptions",
      "Members": [
      {
        "@odata.id": "/redfish/v1/EventService/Subscriptions/1"
      }],
      "Members@odata.count": 1,
      "Name": "Event Subscriptions Collection"
    }

    本例中配置了单个订阅:/redfish/v1/EventService/Subscriptions/1

  2. 可选: 要使用 curl 删除 /redfish/v1/EventService/Subscriptions/1 订阅,请运行以下命令并指定 BMC 用户名和密码:

    $ curl --globoff -L -w "%{http_code} %{url_effective}\n" -k -u <bmc_username>:<password >-H "Content-Type: application/json" -d '{}' -X DELETE https://<bmc_ip_address>/redfish/v1/EventService/Subscriptions/1

    其中:

    bmc_ip_address
    是生成 Redfish 事件的 BMC 的 IP 地址。

11.4.3. 创建裸机事件和 Secret CR

要使用裸机事件,请为存在 Redfish 硬件的主机创建 HardwareEvent 自定义资源(CR)。在 hw-event-proxy 日志中报告硬件事件和错误。

先决条件

  • 安装 OpenShift CLI(oc)。
  • 以具有 cluster-admin 特权的用户身份登录。
  • 安装裸机事件中继。
  • 为 BMC Redfish 硬件创建一个 BMCEventSubscription CR。
注意

不允许多个 HardwareEvent 资源。

流程

  1. 创建 HardwareEvent 自定义资源(CR):

    1. 将以下 YAML 保存到 hw-event.yaml 文件中:

      apiVersion: "event.redhat-cne.org/v1alpha1"
      kind: "HardwareEvent"
      metadata:
        name: "hardware-event"
      spec:
        nodeSelector:
          node-role.kubernetes.io/hw-event: "" 1
        transportHost: "amqp://amq-router-service-name.amq-namespace.svc.cluster.local" 2
        logLevel: "debug" 3
        msgParserTimeout: "10" 4
      1
      必需。使用 nodeSelector 字段来带有指定标签的目标节点,如 node-role.kubernetes.io/hw-event: ""
      2
      必需。使用 AMQP 协议在传输层提供事件的 AMQP 主机。
      3
      可选的。默认值为 debug。在 hw-event-proxy 日志中设置日志级别。可用的日志级别如下: fatalerrorwarninginfodebugtrace
      4
      可选的。为 Message Parser 设置超时值(毫秒)。如果在超时时间内没有响应消息解析请求,原始硬件事件信息会被传递给云原生事件框架。默认值为 10。
    2. 创建 HardwareEvent CR:

      $ oc create -f hardware-event.yaml
  2. 创建一个 BMC 用户名和密码 Secret CR,使硬件事件代理能够访问裸机主机的 Redfish 消息 registry。

    1. 将以下 YAML 保存到 hw-event-bmc-secret.yaml 文件中:

      apiVersion: v1
      kind: Secret
      metadata:
        name: redfish-basic-auth
      type: Opaque
      stringData: 1
        username: <bmc_username>
        password: <bmc_password>
        # BMC host DNS or IP address
        hostaddr: <bmc_host_ip_address>
      1
      stringData 下的各种项目输入纯文本值。
    2. 创建 Secret CR:

      $ oc create -f hw-event-bmc-secret.yaml