我试图使用 Prometheus 监控我们的 Spring boot 应用程序之一,但不幸的是该服务的状态在 ubuntu 服务器中没有启动,它显示了一些错误,例如 –
/prometheus: x509: 由未知权威机构签名的证书,从我本地的 Prometheus 中该服务已启动,并且还能够监视一些 http 请求。
我也遇到过同样的问题。 解决方法:
按照@Shmuel的建议配置 Prometheus 忽略 ssl 验证
global:
scrape_interval: 15s
external_labels:
monitor: 'prometheus'
scrape_configs:
- job_name: 'job-name'
static_configs:
- targets:
- host_name_or_ip_address1
- host_name_or_ip_address2
- host_name_or_ip_address2
scheme: https # to use https instead of http for scraping
tls_config:
insecure_skip_verify: true # This is the key
如果您使用自签名证书,您可以将证书添加到
scrape_configs
下的tls_config
:
global:
scrape_interval: 15s
external_labels:
monitor: 'prometheus'
scrape_configs:
- job_name: 'job-name'
static_configs:
- targets:
- host_name_or_ip_address1
tls_config:
ca_file: /path/to/prometheus.crt
scheme: https
找到普罗米修斯入场秘密: 找到名为 prometheus-kube-prometheus-admission 的秘密。此秘密包含必要的证书。
提取并编码 CA 证书: 解码密钥以检索 CA 证书 (ca.crt)。然后,您需要以 Base64 格式对此证书进行编码,以便进行后续步骤。
修补 MutatingWebhookConfiguration: 使用 kubectl patch 命令更新 mutatingwebhook 配置。将 'xxxx...' 替换为您的 base64 编码的 ca.crt。
kubectl patch mutatingwebhookconfigurations prometheus-kube-prometheus-admission --type='json' -p="[{'op': 'add', 'path': '/webhooks/0/clientConfig/caBundle', 'value':'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}]"
修补 ValidatingWebhookConfiguration: 同样,使用相同的 ca.crt 修补 validatingwebhook 配置。该命令与上面的命令几乎相同,唯一的变化是您要修补的 Webhook 配置的类型。
kubectl patch validatingwebhookconfigurations prometheus-kube-prometheus-admission --type='json' -p="..."
(Use the same JSON payload as in the mutatingwebhook patch command)
重新启动、通量协调或您正在使用的任何技术。
我希望这个解决方案可以帮助任何可能在 Kubernetes 中遇到 Prometheus webhook 类似问题的人。如果您还有任何疑问或需要澄清,请随时询问!