kubernetes中的pod间通信

时间:2017-07-04 12:21:50

标签: kubernetes microservices prometheus

我之前创建了一个包含三个容器的容器,即 prometheus blackbox-exporter python-access-api blackbox-exporter 在端口9115上运行,并抓取 python-access-api 容器生成的目标,该容器在 prometheus 中提醒SSL过期目标证书。现在我想将 blackbox-exporter 移动到另一个pod。我试图通过服务建立此功能,但我现在无法在 prometheus blackbox-exporter 之间建立通信,因为它们位于不同的豆荚因此,我无法对SSL Expiry证书进行调查,因此无法在 prometheus 上看到警报。下面是我使用的yaml文件,任何人都可以指出解决这个问题的方法。请注意,我的配置对普罗米修斯看起来很好,而黑盒和普罗米修斯的吊舱也可单独运行。就像我上面说的那样,我看不到他们彼此沟通。

apiVersion: v1
kind: ReplicationController
metadata:
  name: blackbox-deployment
  labels:
    app: prometheus
spec:
  replicas: 1
  selector:
    app: blackbox
  template:
    metadata:
      name: blackbox
      labels:
        app: blackbox
    spec:
      containers:
      - name: blackbox

Prometheus部署的Yaml文件

apiVersion: v1
kind: ReplicationController
metadata:
  name: python-daemon
  labels:
    app: prometheus-python
spec:
  replicas: 1
  selector:
    app: python
  template:
    metadata:
      name: python
      labels:
        app: python
    spec:
      containers:

我已部署的服务: -

apiVersion: v1
kind: Service
metadata:
  name: prometheus
spec:
  selector:
    app: prometheus
  ports:
  - name: http
    port: 80
    targetPort: 9115
    protocol: TCP

prometheus配置如下

- job_name: blackbox
  params:
    module:
    - http_2xx
  scrape_interval: 1m
  scrape_timeout: 10s
  metrics_path: /probe
  scheme: http
  file_sd_configs:
  - files:
    - /var/suhas/targets.yml
    refresh_interval: 5m
  relabel_configs:
  - source_labels: [__address__]
    separator: ;
    regex: (.*)
    target_label: __param_target
    replacement: $1
    action: replace
  - source_labels: [__param_target]
    separator: ;
    regex: (.*)
    target_label: instance
    replacement: $1
    action: replace
  - source_labels: []
    separator: ;
    regex: (.*)
    target_label: __address__
    replacement: prometheus:9115
    action: replace

1 个答案:

答案 0 :(得分:0)

首先,您需要澄清正在进行的通信。 prometheus是通过端口9115访问blackbox导出器,还是blackbox导出器通过端口80访问prometheus?根据哪个是正确的,服务会有所不同。

在上面的服务中,您正在设置和端点,当通过端口80访问时,它会将流量重定向到您的blackbox-exporter应用程序的端口9115。我将假设prometheus正在访问blackbox-exporter以获得其余答案。

prometheus会通过端口9115或端口80访问blackbox导出器。在我看来,在您的初始设置中,prometheus将使用端口9115进行访问。因此,没有理由将服务中的端口更改为80.您是否可以尝试在服务文件中设置port: 9115

另外,请确保将prometheus配置为使用正确的地址。我假设它之前使用的是127.0.0.1:9115,现在需要prometheus:9115(因为你将服务命名为prometheus,这可能有点令人困惑)。