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 对象中包含密码的密钥。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部