【问题标题】:How I can send a credentials json file to kubernetes pod?如何将凭证 json 文件发送到 kubernetes pod?
【发布时间】:2021-05-15 17:28:26
【问题描述】:

我在 Kubernetes 集群中使用 Elastic Heartbeat。

我正在尝试将谷歌云平台模块设置为 Heartbeat,文档说:

    metricbeat.modules:
    - module: googlecloud
      metricsets:
        - compute
      region: "us-"
      project_id: "your project id"
      credentials_file_path: "your JSON credentials file path"
      exclude_labels: false
      period: 1m

我有我的 credentials.json 文件来访问 GCP,但是,我无法使用 Heartbeat 将此凭据放入 kubernetes pod。

我尝试使用 kubernetes 密码,但模块配置不允许这样做。只允许放一条路径。

如何将此凭据放入我的心跳 pod?

谢谢!

【问题讨论】:

    标签: elasticsearch kubernetes heartbeat


    【解决方案1】:

    解决了!

    我用我的 credentials.json 文件创建了一个秘密,并将秘密作为卷安装在 pod 中。

    配置:

    secret.yaml:

    apiVersion: v1
    kind: Secret
    metadata:
      name: credentials-secret
    type: Opaque
    stringData:
      sa_json: |
        {
          "type": "service_account",
          "project_id": "erased",
          "private_key_id": "erased",
          "private_key": "-----BEGIN PRIVATE KEY-----erased-----END PRIVATE KEY-----\n",
          "client_email": "erased",
          "client_id": "erased",
          "auth_uri": "https://accounts.google.com/o/oauth2/auth",
          "token_uri": "https://oauth2.googleapis.com/token",
          "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
          "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxxxx.iam.gserviceaccount.com"
        }
    
    

    deployment.yaml:

    ---
              volumeMounts:
              - mountPath: /etc/gcp
                name: service-account-credentials-volume
                readOnly: true
    ---
    ---
    ---
            volumes:
            - name: service-account-credentials-volume
              secret:
                secretName: credentials-secret
                items:
                - key: sa_json
                  path: credentials.json
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 2021-04-23
      • 2023-03-10
      • 2018-01-11
      • 2019-02-23
      • 1970-01-01
      • 2020-08-24
      相关资源
      最近更新 更多