4.4. 为用户工作负载监控配置指标


配置指标集合,以监控集群组件和您自己的工作负载的执行方式。

您可以将最接近的指标发送到远程系统进行长期存储,并将集群 ID 标签添加到指标,以识别来自不同集群的数据。

其他资源

4.4.1. 配置远程写入存储

您可以配置远程写入存储,使 Prometheus 能够将最接近的指标发送到远程系统,以进行长期存储。这样做不会影响 Prometheus 存储指标的方式和时长。

先决条件

  • 您可以使用具有 cluster-admin 集群角色或具有 openshift-user-workload-monitoring 项目中的 user-workload-monitoring-config-edit 角色的用户访问集群。
  • 集群管理员为用户定义的项目启用了监控。
  • 已安装 OpenShift CLI(oc)。
  • 您已设置了一个远程写入兼容端点(如 Thanos),并且知道端点 URL。有关与远程写入功能兼容的端点的信息,请参阅 Prometheus 远程端点和存储文档

    重要

    红帽只提供配置远程写入发送者的信息,而不提供有关配置接收器端点的指导。客户负责设置自己的端点,这些端点与远程写入兼容。端点接收器配置的问题不包括在红帽产品支持中。

  • 您已为远程写入端点在 Secret 对象中设置身份验证凭证。您必须在 openshift-user-workload-monitoring 命名空间中创建 secret。

    警告

    要减少安全风险,请使用 HTTPS 和身份验证向端点发送指标。

流程

  1. 编辑 openshift-user-workload-monitoring 项目中的 user-workload-monitoring-config 配置映射:

    $ oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-config
  2. data/config.yaml/prometheus 下添加一个 remoteWrite: 部分,如下例所示:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: user-workload-monitoring-config
      namespace: openshift-user-workload-monitoring
    data:
      config.yaml: |
        prometheus:
          remoteWrite:
          - url: "https://remote-write-endpoint.example.com" 1
            <endpoint_authentication_credentials> 2
    1
    远程写入端点的 URL。
    2
    端点的身份验证方法和凭据。目前支持的身份验证方法有 AWS 签名版本 4,使用 HTTP Authorization 请求标头、基本身份验证、OAuth 2.0 和 TLS 客户端进行身份验证。有关支持的身份验证方法示例配置,请参阅支持的远程写入身份验证设置
  3. 在身份验证凭证后添加 write relabel 配置值:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: user-workload-monitoring-config
      namespace: openshift-user-workload-monitoring
    data:
      config.yaml: |
        prometheus:
          remoteWrite:
          - url: "https://remote-write-endpoint.example.com"
            <endpoint_authentication_credentials>
            writeRelabelConfigs:
            - <your_write_relabel_configs> 1
    1
    为您要发送到远程端点的指标添加配置。

    转发一个名为 my_metric 的单个指标的示例

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: user-workload-monitoring-config
      namespace: openshift-user-workload-monitoring
    data:
      config.yaml: |
        prometheus:
          remoteWrite:
          - url: "https://remote-write-endpoint.example.com"
            writeRelabelConfigs:
            - sourceLabels: [__name__]
              regex: 'my_metric'
              action: keep

    my_namespace 命名空间中转发名为 my_metric_1my_metric_2 的指标示例

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: user-workload-monitoring-config
      namespace: openshift-user-workload-monitoring
    data:
      config.yaml: |
        prometheus:
          remoteWrite:
          - url: "https://remote-write-endpoint.example.com"
            writeRelabelConfigs:
            - sourceLabels: [__name__,namespace]
              regex: '(my_metric_1|my_metric_2);my_namespace'
              action: keep

  4. 保存文件以使改变生效。新的配置会被自动应用。

4.4.1.1. 支持的远程写入身份验证设置

您可以使用不同的方法通过远程写入端点进行身份验证。目前支持的身份验证方法有 AWS 签名版本 4、基本身份验证、授权、OAuth 2.0 和 TLS 客户端。下表提供有关用于远程写入的受支持身份验证方法的详情。

身份验证方法配置映射字段描述

AWS 签名版本 4

sigv4

此方法使用 AWS 签名版本 4 身份验证为请求签名。您不能搭配授权、OAuth 2.0 或基本身份验证同时使用此方法。

基本身份验证(Basic authentication)

basicAuth

基本身份验证使用配置的用户名和密码在每个远程写入请求上设置授权标头。

授权

授权

授权使用配置的令牌在每个远程写入请求上设置 Authorization 标头。

OAuth 2.0

oauth2

OAuth 2.0 配置使用客户端凭据授予类型。Prometheus 使用指定的客户端 ID 和客户端 secret 从 tokenUrl 获取访问令牌来访问远程写入端点。您不能与授权、AWS 签名版本 4 或基本身份验证同时使用此方法。

TLS 客户端

tlsConfig

TLS 客户端配置指定 CA 证书、客户端证书和客户端密钥文件信息,用于使用 TLS 与远程写入端点服务器进行身份验证。示例配置假定您已创建了 CA 证书文件、客户端证书文件和客户端密钥文件。

4.4.1.2. 远程写入身份验证设置示例

以下示例展示了可用于连接到远程写入端点的不同身份验证设置。每个示例还演示了如何配置包含身份验证凭据和其他相关设置的对应 Secret 对象。每个示例配置用于监控 openshift-user-workload-monitoring 命名空间中的用户定义的项目的身份验证。

4.4.1.2.1. AWS 签名版本 4 验证的 YAML 示例

以下显示了 openshift-user-workload-monitoring 命名空间中名为 sigv4-credentialssigv4 secret 的设置。

apiVersion: v1
kind: Secret
metadata:
  name: sigv4-credentials
  namespace: openshift-user-workload-monitoring
stringData:
  accessKey: <AWS_access_key> 1
  secretKey: <AWS_secret_key> 2
type: Opaque
1
AWS API 访问密钥。
2
AWS API secret 密钥。

下面显示了一个 AWS Signature Version 4 远程写入身份验证设置示例,它使用 openshift-user-workload-monitoring 命名空间中名为 sigv4-credentialsSecret 对象:

apiVersion: v1
kind: ConfigMap
metadata:
  name: user-workload-monitoring-config
  namespace: openshift-user-workload-monitoring
data:
  config.yaml: |
    prometheus:
      remoteWrite:
      - url: "https://authorization.example.com/api/write"
        sigv4:
          region: <AWS_region> 1
          accessKey:
            name: sigv4-credentials 2
            key: accessKey 3
          secretKey:
            name: sigv4-credentials 4
            key: secretKey 5
          profile: <AWS_profile_name> 6
          roleArn: <AWS_role_arn> 7
1
AWS 区域。
2 4
包含 AWS API 访问凭证的 Secret 对象的名称。
3
在指定 Secret 对象中包含 AWS API 访问密钥的密钥。
5
在指定的 Secret 对象中包含 AWS API secret 键的密钥。
6
用于验证的 AWS 配置集的名称。
7
分配给角色的 Amazon 资源名称(ARN)的唯一标识符。
4.4.1.2.2. 用于基本身份验证的 YAML 示例

以下显示了 openshift-user-workload-monitoring 命名空间中名为 rw-basic-authSecret 对象的基本身份验证设置示例:

apiVersion: v1
kind: Secret
metadata:
  name: rw-basic-auth
  namespace: openshift-user-workload-monitoring
stringData:
  user: <basic_username> 1
  password: <basic_password> 2
type: Opaque
1
用户名。
2
密码。

以下示例显示了使用 openshift-user-workload-monitoring 命名空间中名为 rw-basic-authSecret 对象的 basicAuth 远程写入配置。它假设您已为端点设置了身份验证凭据。

apiVersion: v1
kind: ConfigMap
metadata:
  name: user-workload-monitoring-config
  namespace: openshift-user-workload-monitoring
data:
  config.yaml: |
    prometheus:
      remoteWrite:
      - url: "https://basicauth.example.com/api/write"
        basicAuth:
          username:
            name: rw-basic-auth 1
            key: user 2
          password:
            name: rw-basic-auth 3
            key: password 4
1 3
包含身份验证凭据的 Secret 对象的名称。
2
在指定的 Secret 对象中包含用户名的密钥。
4
在指定 Secret 对象中包含密码的密钥。
4.4.1.2.3. 使用 Secret 对象通过 bearer 令牌进行身份验证的 YAML 示例

以下显示了 openshift-user-workload-monitoring 命名空间中名为 rw-bearer-authSecret 对象的 bearer 令牌设置:

apiVersion: v1
kind: Secret
metadata:
  name: rw-bearer-auth
  namespace: openshift-user-workload-monitoring
stringData:
  token: <authentication_token> 1
type: Opaque
1
身份验证令牌。

以下显示了在 openshift-user-workload-monitoring 命名空间中使用名为 rw-bearer-authSecret 对象的 bearer 令牌配置映射设置示例:

apiVersion: v1
kind: ConfigMap
metadata:
  name: user-workload-monitoring-config
  namespace: openshift-user-workload-monitoring
data:
  config.yaml: |
    enableUserWorkload: true
    prometheus:
      remoteWrite:
      - url: "https://authorization.example.com/api/write"
        authorization:
          type: Bearer 1
          credentials:
            name: rw-bearer-auth 2
            key: token 3
1
请求的验证类型。默认值为 Bearer
2
包含身份验证凭据的 Secret 对象的名称。
3
在指定的 Secret 对象中包含身份验证令牌的密钥。
4.4.1.2.4. 用于 OAuth 2.0 验证的 YAML 示例

以下显示了 openshift-user-workload-monitoring 命名空间中名为 oauth2-credentialsSecret 对象的 OAuth 2.0 设置示例:

apiVersion: v1
kind: Secret
metadata:
  name: oauth2-credentials
  namespace: openshift-user-workload-monitoring
stringData:
  id: <oauth2_id> 1
  secret: <oauth2_secret> 2
type: Opaque
1
Oauth 2.0 ID。
2
OAuth 2.0 secret。

下面显示了一个 oauth2 远程写入身份验证示例配置,它使用 openshift-user-workload-monitoring 命名空间中名为 oauth2-credentialsSecret 对象:

apiVersion: v1
kind: ConfigMap
metadata:
  name: user-workload-monitoring-config
  namespace: openshift-user-workload-monitoring
data:
  config.yaml: |
    prometheus:
      remoteWrite:
      - url: "https://test.example.com/api/write"
        oauth2:
          clientId:
            secret:
              name: oauth2-credentials 1
              key: id 2
          clientSecret:
            name: oauth2-credentials 3
            key: secret 4
          tokenUrl: https://example.com/oauth2/token 5
          scopes: 6
          - <scope_1>
          - <scope_2>
          endpointParams: 7
            param1: <parameter_1>
            param2: <parameter_2>
1 3
对应的 Secret 对象的名称。请注意,ClientId 可以引用 ConfigMap 对象,但 clientSecret 必须引用 Secret 对象。
2 4
在指定 Secret 对象中包含 OAuth 2.0 凭证的密钥。
5
用于通过指定的 clientIdclientSecret 获取令牌的 URL。
6
授权请求的 OAuth 2.0 范围。这些范围限制了令牌可以访问的数据。
7
授权服务器所需的 OAuth 2.0 授权请求参数。
4.4.1.2.5. TLS 客户端身份验证的 YAML 示例

以下显示了 openshift-user-workload-monitoring 命名空间中名为 mtls-bundletls Secret 对象的 TLS 客户端设置示例。

apiVersion: v1
kind: Secret
metadata:
  name: mtls-bundle
  namespace: openshift-user-workload-monitoring
data:
  ca.crt: <ca_cert> 1
  client.crt: <client_cert> 2
  client.key: <client_key> 3
type: tls
1
Prometheus 容器中用于验证服务器证书的 CA 证书。
2
用于与服务器进行身份验证的客户端证书。
3
客户端密钥。

以下示例显示了使用名为 mtls-bundle 的 TLS Secret 对象的 tlsConfig 远程写入身份验证配置。

apiVersion: v1
kind: ConfigMap
metadata:
  name: user-workload-monitoring-config
  namespace: openshift-user-workload-monitoring
data:
  config.yaml: |
    prometheus:
      remoteWrite:
      - url: "https://remote-write-endpoint.example.com"
        tlsConfig:
          ca:
            secret:
              name: mtls-bundle 1
              key: ca.crt 2
          cert:
            secret:
              name: mtls-bundle 3
              key: client.crt 4
          keySecret:
            name: mtls-bundle 5
            key: client.key 6
1 3 5
包含 TLS 身份验证凭证的对应 Secret 对象的名称。请注意,cacert 可以引用 ConfigMap 对象,但 keySecret 必须引用 Secret 对象。
2
指定 Secret 对象中的键,其中包含端点的 CA 证书。
4
指定 Secret 对象中的键,其中包含端点的客户端证书。
6
包含客户端密钥 secret 的指定 Secret 对象中的密钥。

4.4.1.3. 远程写入队列配置示例

您可以使用 queueConfig 对象来远程写入,以调优远程写入队列参数。以下示例显示了 queue 参数,以及它们用于监控 openshift-user-workload-monitoring 命名空间中的用户定义的项目的默认值。

使用默认值进行远程写入参数配置示例

apiVersion: v1
kind: ConfigMap
metadata:
  name: user-workload-monitoring-config
  namespace: openshift-user-workload-monitoring
data:
  config.yaml: |
    prometheus:
      remoteWrite:
      - url: "https://remote-write-endpoint.example.com"
        <endpoint_authentication_credentials>
        queueConfig:
          capacity: 10000 1
          minShards: 1 2
          maxShards: 50 3
          maxSamplesPerSend: 2000 4
          batchSendDeadline: 5s 5
          minBackoff: 30ms 6
          maxBackoff: 5s 7
          retryOnRateLimit: false 8
          sampleAgeLimit: 0s 9

1
在从队列中丢弃前,每个分片要缓冲的样本数量。
2
最小分片数量。
3
最大分片数量。
4
每个发送的最大样本数。
5
样本在缓冲区中等待的最长时间。
6
在重试一个失败的请求前等待的初始时间。每次重试的时间都会加倍,最长为 maxbackoff 时间。
7
在重试一个失败的请求前等待的最长时间。
8
将此参数设为 true,以在从远程写入存储接收 429 状态代码后重试请求。
9
早于 sampleAgeLimit 限制的样本会从队列中丢弃。如果值未定义,或设置为 0s,则会忽略该参数。

4.4.2. 为指标创建集群 ID 标签

您可以通过在 openshift-user-workload-monitoring 命名空间中为 user-workload-monitoring-config 配置映射中添加远程写入存储的 write_relabel 设置来为指标创建集群 ID 标签。

注意

当 Prometheus 提取公开 namespace 标签的用户工作负载目标时,系统会将此标签存储为 exported_namespace。此行为可确保最终命名空间标签值等于目标 pod 的命名空间。您不能将 PodMonitorServiceMonitor 对象的 honorLabels 字段的值设置为 true 来覆盖此默认配置。

先决条件

  • 您可以使用具有 cluster-admin 集群角色的用户访问集群,也可以使用在 openshift-user-workload-monitoring 项目中具有 user-workload-monitoring-config-edit 角色的用户访问集群。
  • 集群管理员为用户定义的项目启用了监控。
  • 已安装 OpenShift CLI(oc)。
  • 您已配置了远程写入存储。

流程

  1. 编辑 openshift-user-workload-monitoring 项目中的 user-workload-monitoring-config 配置映射:

    $ oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-config
  2. data/config.yaml/prometheus/remoteWrite 下的 writeRelabelConfigs: 部分中,添加集群 ID 重新标记配置值:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: user-workload-monitoring-config
      namespace: openshift-user-workload-monitoring
    data:
      config.yaml: |
        prometheus:
          remoteWrite:
          - url: "https://remote-write-endpoint.example.com"
            <endpoint_authentication_credentials>
            writeRelabelConfigs: 1
              - <relabel_config> 2
    1
    为您要发送到远程端点的指标添加写入重新标记配置列表。
    2
    替换发送到远程写入端点的指标的标签配置。

    以下示例演示了如何使用集群 ID 标签 cluster_id 转发指标:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: user-workload-monitoring-config
      namespace: openshift-user-workload-monitoring
    data:
      config.yaml: |
        prometheus:
          remoteWrite:
          - url: "https://remote-write-endpoint.example.com"
            writeRelabelConfigs:
            - sourceLabels:
              - __tmp_openshift_cluster_id__ 1
              targetLabel: cluster_id 2
              action: replace 3
    1
    系统最初应用名为 __tmp_openshift_cluster_id__ 的临时集群 ID 源标签。此临时标签由您指定的集群 ID 标签名称替换。
    2
    指定发送到远程写入存储的指标的集群 ID 标签名称。如果您使用指标已存在的标签名称,则该值会使用这个集群 ID 标签的名称覆盖。对于标签名称,不要使用 __tmp_openshift_cluster_id__。最后重新标记步骤会删除使用此名称的标签。
    3
    replace write relabel 操作,将临时标签替换为传出指标的目标标签。这个操作是默认行为,如果没有指定任何操作,则会被应用。
  3. 保存文件以使改变生效。新的配置会被自动应用。

4.4.3. 为用户定义的项目设置指标集合

您可以创建一个 ServiceMonitor 资源,从用户定义的项目中的服务端点提取指标。这假设您的应用程序使用 Prometheus 客户端库向 /metrics 规范名称公开指标。

本节介绍了如何在用户定义的项目中部署示例服务,然后创建一个 ServiceMonitor 资源来定义应该如何监控该服务。

4.4.3.1. 部署示例服务

要为用户定义的项目中服务测试监控,您可以部署示例服务。

先决条件

  • 您可以使用具有 cluster-admin 集群角色或具有命名空间管理权限的用户身份访问集群。

流程

  1. 为服务配置创建 YAML 文件。在本例中,该文件名为 prometheus-example-app.yaml
  2. 在该文件中添加以下部署和服务配置详情:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: ns1
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: prometheus-example-app
      name: prometheus-example-app
      namespace: ns1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: prometheus-example-app
      template:
        metadata:
          labels:
            app: prometheus-example-app
        spec:
          containers:
          - image: ghcr.io/rhobs/prometheus-example-app:0.4.2
            imagePullPolicy: IfNotPresent
            name: prometheus-example-app
    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: prometheus-example-app
      name: prometheus-example-app
      namespace: ns1
    spec:
      ports:
      - port: 8080
        protocol: TCP
        targetPort: 8080
        name: web
      selector:
        app: prometheus-example-app
      type: ClusterIP

    此配置会在用户定义的 ns1 项目中部署名为 prometheus-example-app 的服务。此服务会公开自定义 version 指标。

  3. 将配置应用到集群:

    $ oc apply -f prometheus-example-app.yaml

    部署该服务需要一些时间。

  4. 您可以检查该 Pod 是否正在运行:

    $ oc -n ns1 get pod

    输出示例

    NAME                                      READY     STATUS    RESTARTS   AGE
    prometheus-example-app-7857545cb7-sbgwq   1/1       Running   0          81m

4.4.3.2. 指定如何监控服务

要使用服务公开的指标,需要将 OpenShift Container Platform 监控配置为从 /metrics 端点中提取指标。您可以使用一个 ServiceMonitor 自定义资源定义(CRD)应该如何监控服务,或使用一个 PodMonitor CRD 指定应该如何监控 pod。前者需要 Service 对象,而后者则不需要,允许 Prometheus 直接从 Pod 公开的指标端点中提取指标。

此流程演示了如何为用户定义的项目中的服务创建 ServiceMonitor 资源。

先决条件

  • 您可以使用具有 cluster-admin 集群角色或 monitoring-edit 集群角色的用户访问集群。
  • 您已为用户定义的项目启用了监控。
  • 在本例中,您已在 ns1 项目中部署了 prometheus-example-app 示例服务。

    注意

    prometheus-example-app 示例服务不支持 TLS 身份验证。

流程

  1. 创建名为 example-app-service-monitor.yaml 的新 YAML 配置文件。
  2. ServiceMonitor 资源添加到 YAML 文件中。以下示例创建一个名为 prometheus-example-monitor 的服务监控器,用于提取 ns1 命名空间中的 prometheus-example-app 服务公开的指标:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: prometheus-example-monitor
      namespace: ns1 1
    spec:
      endpoints:
      - interval: 30s
        port: web 2
        scheme: http
      selector: 3
        matchLabels:
          app: prometheus-example-app
    1
    指定服务运行的用户定义的命名空间。
    2
    指定要由 Prometheus 提取的端点端口。
    3
    配置选择器,根据其元数据标签匹配您的服务。
    注意

    用户定义的命名空间中的 ServiceMonitor 资源只能发现同一命名空间中的服务。也就是说,ServiceMonitor 资源的 namespaceSelector 字段总是被忽略。

  3. 将配置应用到集群:

    $ oc apply -f example-app-service-monitor.yaml

    部署 ServiceMonitor 资源需要一些时间。

  4. 验证 ServiceMonitor 资源是否正在运行:

    $ oc -n <namespace> get servicemonitor

    输出示例

    NAME                         AGE
    prometheus-example-monitor   81m

4.4.3.3. 服务端点身份验证设置示例

您可以使用 ServiceMonitorPodMonitor 自定义资源定义(CRD) 为用户定义的项目监控配置服务端点身份验证。

以下示例显示了 ServiceMonitor 资源的不同身份验证设置。每个示例演示了如何配置包含身份验证凭据和其他相关设置的对应 Secret 对象。

4.4.3.3.1. 使用 bearer 令牌的 YAML 身份验证示例

以下示例显示了 ns1 命名空间中名为 example-bearer-authSecret 对象的 bearer 令牌设置:

bearer 令牌 secret 示例

apiVersion: v1
kind: Secret
metadata:
  name: example-bearer-auth
  namespace: ns1
stringData:
  token: <authentication_token> 1

1
指定身份验证令牌。

以下示例显示了 ServiceMonitor CRD 的 bearer 令牌身份验证设置。这个示例使用名为 example-bearer-authSecret 对象:

bearer 令牌身份验证设置示例

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus-example-monitor
  namespace: ns1
spec:
  endpoints:
  - authorization:
      credentials:
        key: token 1
        name: example-bearer-auth 2
    port: web
  selector:
    matchLabels:
      app: prometheus-example-app

1
在指定的 Secret 对象中包含身份验证令牌的密钥。
2
包含身份验证凭据的 Secret 对象的名称。
重要

不要使用 bearerTokenFile 来配置 bearer 令牌。如果使用 bearerTokenFile 配置,ServiceMonitor 资源将被拒绝。

4.4.3.3.2. 用于基本身份验证的 YAML 示例

以下示例显示了 ns1 命名空间中名为 example-basic-authSecret 对象基本身份验证设置:

基本身份验证 secret 示例

apiVersion: v1
kind: Secret
metadata:
  name: example-basic-auth
  namespace: ns1
stringData:
  user: <basic_username> 1
  password: <basic_password>  2

1
指定用于身份验证的用户名。
2
指定用于身份验证的密码。

以下示例显示了 ServiceMonitor CRD 的基本身份验证设置。这个示例使用名为 example-basic-authSecret 对象:

基本身份验证设置示例

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus-example-monitor
  namespace: ns1
spec:
  endpoints:
  - basicAuth:
      username:
        key: user 1
        name: example-basic-auth 2
      password:
        key: password 3
        name: example-basic-auth 4
    port: web
  selector:
    matchLabels:
      app: prometheus-example-app

1
在指定的 Secret 对象中包含用户名的密钥。
2 4
包含基本身份验证的 Secret 对象的名称。
3
在指定 Secret 对象中包含密码的密钥。
4.4.3.3.3. 使用 OAuth 2.0 的 YAML 身份验证示例

以下示例显示了 ns1 命名空间中名为 example-oauth2Secret 对象的 OAuth 2.0 设置:

OAuth 2.0 secret 示例

apiVersion: v1
kind: Secret
metadata:
  name: example-oauth2
  namespace: ns1
stringData:
  id: <oauth2_id> 1
  secret: <oauth2_secret> 2

1
指定 Oauth 2.0 ID。
2
指定 Oauth 2.0 secret。

以下示例显示了 ServiceMonitor CRD 的 OAuth 2.0 身份验证设置。这个示例使用名为 example-oauth2Secret 对象:

OAuth 2.0 身份验证设置示例

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus-example-monitor
  namespace: ns1
spec:
  endpoints:
  - oauth2:
      clientId:
        secret:
          key: id 1
          name: example-oauth2 2
      clientSecret:
        key: secret 3
        name: example-oauth2 4
      tokenUrl: https://example.com/oauth2/token 5
    port: web
  selector:
    matchLabels:
      app: prometheus-example-app

1
在指定 Secret 对象中包含 OAuth 2.0 ID 的密钥。
2 4
包含 OAuth 2.0 凭证的 Secret 对象的名称。
3
在指定 Secret 对象中包含 OAuth 2.0 secret 的密钥。
5
用于通过指定的 clientIdclientSecret 获取令牌的 URL。
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.