我们有一个 openshift 集群,其中安装了 prometheus 操作员监控堆栈。我们想使用黑盒导出器探测 Spring Boot 应用程序的
actuator/health
端点。
这是我到目前为止所做的:
在我们用于 prometheus 操作符的命名空间中部署黑盒导出器。
Service
和ConfigMap
已准备就绪,http_2xx
中定义了configMap
模块,导出器正在运行。我有 2 个命名空间(或项目),其中部署了 1-1 个应用程序,这些是相同的应用程序。我在一个命名空间中创建了一个 Probe
,在另一个命名空间中创建了一个 serviceMonitor
。探测器使用 staticTarget
config 来探测目标,serviceMonitor 使用标签来动态执行此操作。
我的问题是每次探测尝试都失败。
serviceMonitor 日志显示以下内容:
`level=info msg="Invalid HTTP response status code, wanted 2xx" status_code=400`
我很确定会发生这种情况,因为这些是 https 端点,但如果我在 serviceMonitor 配置中添加“scheme: https”行,它就不起作用。
探测器的内容如下:
`level=error msg="Error for HTTP request" err="Get \"https://appIP:port/actuator/health\": tls: failed to verify certificate: x509: certificate signed by unknown authority"`
到目前为止,我只尝试让探针工作,我不知道如何使用 serviceMonitor。
我尝试为探针提供一个服务 ca 来使用,但没有成功。我给了它应用程序使用的证书和密钥,但它不起作用,同样如此。
知道我应该做什么吗?配置如下。
您会注意到探针配置现在没有 ca 对象,但它给出了相同的日志。
如果有人能帮我解决这个问题,我真的很感激,这让我发疯:D
(注:
tlsConfig: insecureSkipVerify: true
并没有跳过验证过程,这很奇怪)
黑盒导出器 yaml:
data:
blackbox.yaml: |
modules:
http_2xx:
http:
no_follow_redirects: true
method: GET
preferred_ip_protocol: ip4
valid_http_versions:
- HTTP/1.1
- HTTP/2
valid_status_codes: []
tls_config:
insecure_skip_verify: true
prober: http
timeout: 10s
serviceMonitor yaml:
spec:
endpoints:
- interval: 30s
params:
module:
- http_2xx
path: /probe
relabelings:
- action: replace
sourceLabels:
- __address__
targetLabel: __param_target
- action: replace
replacement: 'exporter:port'
targetLabel: __address__
- action: replace
sourceLabels:
- __param_target
targetLabel: instance
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
scrapeTimeout: 10s
jobLabel: jobLabel
selector:
matchLabels:
app.kubernetes.io/component: component
探测yaml:
spec:
interval: 30s
module: http_2xx
prober:
path: /probe
url: 'exporter.namespace.svc:port'
targets:
staticConfig:
static:
- 'https://app.namespace.svc:port/actuator/health'
tlsConfig:
cert:
secret:
key: key
name: secret-name
keySecret:
key: key
name: secret-name
手动调用黑盒导出器会这样说:
Logs for the probe:
ts=2023-12-07T10:24:46.576847865Z caller=main.go:181 module=http_2xx target=https://app.namespace.svc:port level=info msg="Beginning probe" probe=http timeout_seconds=119.5
ts=2023-12-07T10:24:46.576945405Z caller=http.go:328 module=http_2xx target=https://app.namespace.svc:port level=info msg="Resolving target address" target=app.namespace.svc ip_protocol=ip4
ts=2023-12-07T10:24:46.615450737Z caller=http.go:328 module=http_2xx target=https://app.namespace.svc:port level=info msg="Resolved target address" target=app.namespace.svc ip=IP_of_service
ts=2023-12-07T10:24:46.615543908Z caller=client.go:252 module=http_2xx target=https://app.namespace.svc:port level=info msg="Making HTTP request" url=https://IPaddress:port host=app.namespace.svc:port
ts=2023-12-07T10:24:46.624148963Z caller=handler.go:120 module=http_2xx target=https://app.namespace.svc:port level=error msg="Error for HTTP request" err="Get \"https://IPaddress:port\": tls: failed to verify certificate: x509: certificate signed by unknown authority"
ts=2023-12-07T10:24:46.624187979Z caller=handler.go:120 module=http_2xx target=https://app.namespace.svc:port level=info msg="Response timings for roundtrip" roundtrip=0 start=2023-12-07T10:24:46.618548821Z dnsDone=2023-12-07T10:24:46.618548821Z connectDone=2023-12-07T10:24:46.619955324Z gotConn=0001-01-01T00:00:00Z responseStart=0001-01-01T00:00:00Z tlsStart=2023-12-07T10:24:46.619998796Z tlsDone=2023-12-07T10:24:46.624134551Z end=0001-01-01T00:00:00Z
ts=2023-12-07T10:24:46.62420857Z caller=main.go:181 module=http_2xx target=https://app.namespace.svc:port level=error msg="Probe failed" duration_seconds=0.047321017
我遇到了类似的问题(“获取“https://IP地址:端口”:tls:无法验证证书:x509:由未知机构签名的证书”)并通过以下方式解决:
1-将缺少的根证书和中间证书添加到 /etc/pki/ca-trust/source/anchors/ 目录 2-运行 update-ca-trust 3-将证书颁发机构文件的以下配置添加到 blackbox.yml 配置文件
https_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: [] # Defaults to 2xx
method: GET
fail_if_ssl: false
fail_if_not_ssl: true
preferred_ip_protocol: "ip4" # defaults to "ip6"
ip_protocol_fallback: false # no fallback to "ip6"
tls_config:
ca_file: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem