【问题标题】:Monitoring Kubernetes cluster using prometheus outside the k8 cluster在 k8 集群外使用 prometheus 监控 Kubernetes 集群
【发布时间】:2019-10-22 11:27:42
【问题描述】:
  • 我们有 kubernetes 集群,其中我有服务帐户“kube”,命名空间“monitoring”,并创建了集群角色绑定来监控集群
  • 我们在集群外部的 linux 系统(本地)上安装了 prometheus,并使用“root”进行安装
  • 当我尝试使用 ca.crt 和用户 token(由 kubernetes 管理员提供)通过 https api 连接到 k8 集群时,它会引发多个错误。

错误信息:

component="discovery manager scrape" msg="Cannot create service discovery" err="unable to use specified CA cert /root/prometheus/ca.crt" type=*kubernetes.SDConfig

component="discovery manager scrape" msg="Cannot create service discovery" err="unable to use specified CA cert /root/prometheus/ca.crt" type=*kubernetes.SDConfig

普罗米修斯配置:


  - job_name: 'kubernetes-apiservers'
    scheme: https
    tls_config:
      ca_file: /root/prometheus/ca.crt
    bearer_token_file: /root/prometheus/user_token
    kubernetes_sd_configs:
    - role: endpoints
      api_server: https://example.com:1234
      bearer_token_file: /root/prometheus/user_token
      tls_config:
        ca_file: /root/prometheus/prometheus-2.12.0.linux-amd64/ca.crt
    relabel_configs:
    - source_labels: [monitoring, monitoring-sa, 6443]
      action: keep
      regex: default;kubernetes;https

  - job_name: 'kubernetes-nodes'
    scheme: https
    tls_config:
        ca_file: /root/prometheus/ca.crt
    bearer_token_file: /root/prometheus/user_token

    kubernetes_sd_configs:
    - role: node
      api_server: https://example.com:1234
      bearer_token_file: /root/prometheus/user_token
      tls_config:
        ca_file: /root/prometheus/ca.crt
    relabel_configs:
    - action: labelmap
      regex: __meta_kubernetes_node_label_(.+)
    - target_label: __address__
      replacement: https://example.com:1234
    - source_labels: [__meta_kubernetes_node_name]
      regex: (.+)
      target_label: __metrics_path__
      replacement: /api/v1/nodes/${1}/proxy/metrics

【问题讨论】:

  • 普罗米修斯的版本是多少?
  • 2.12.0 @KamolHasan
  • @KamolHasan 与 2.13.1 相同的错误

标签: kubernetes monitoring prometheus


【解决方案1】:

你面临的主要问题是:"unable to use specified CA cert /root/prometheus/ca.crt"

最近有人遇到了同样的问题: https://github.com/prometheus/prometheus/issues/6015#issuecomment-532058465

他通过重新安装新版本解决了这个问题。

版本2.13.1 已发布。尝试安装最新版本,它也可能解决您的问题。

【讨论】:

  • 我可以尝试一下....但是由于我对 prometheus 很陌生,你能告诉我从外部 prometheus 连接到 k8 集群需要什么吗(现在使用 user_token 和 ca.crt )。您提供的链接正在使用 ca_file、cert_file、key_file ,我是否也需要使用所有这些。最后,我的配置看起来不错吗?
【解决方案2】:

您的ca.crt 很可能仍为base64 格式,因为在描述它们时,秘密是以这种方式编码的,正如here 所解释的那样。

【讨论】:

    【解决方案3】:

    可能您的ca.crt 有错误,请检查您的 ca cert 文件,确保此文件格式如下:

    -----BEGIN CERTIFICATE-----
    xxxxx
    -----END CERTIFICATE-----
    

    我认为您的ca.crt 是由kubectl get serviceaccount -o yaml 获取的,但这是您的kubernetes 集群的公钥,因此,如果您想获取令牌,可以在yaml 文件中指定serviceAccountName新的Deployment,像这样:

    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: test
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: test
            version: v1
        spec:
          serviceAccountName: prometheus
          containers:
          - name: test
            image: alpine
            imagePullPolicy: Always
            command: ["ping", "127.0.0.1"]
          imagePullSecrets:
            - name: harbor-secret
          restartPolicy: Always
    

    然后,在/var/run/secrets/kubernetes.io/serviceaccount/ 下获取您的tokenca.crt

    【讨论】:

      猜你喜欢
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 2020-05-06
      • 1970-01-01
      相关资源
      最近更新 更多