【问题标题】:How to access IP address & port of node in another node in Kubernetes如何在 Kubernetes 的另一个节点中访问节点的 IP 地址和端口
【发布时间】:2020-05-06 16:51:40
【问题描述】:

我有一个包含 2 个 pod 的应用程序,其中一个 pod 正在摄取数据,而另一个想要使用它。 我正在尝试使用单节点 Kubernetes 设置。 现在:

`in pod1` 
        - name: ingest_cfg
        value: zmq_tcp,0.0.0.0:9000 [where pod1 is publishing on port 9000, even this I want to be dynamically configurable]

`in pod2`
        - name: ingest_cfg
        value: "zmq_tcp,IPadd:pv" [where IPadd should be Ip address where pod 1 is publishing and pv is port number where pod1 has published]

现在,我需要知道如何在代码中进行配置。我不想硬编码 IP 地址和端口。任何指针都会非常有帮助。 我尝试使用服务名称,但它指向集群 IP 地址。

【问题讨论】:

    标签: kubernetes service dns


    【解决方案1】:

    我建议您为每个应用使用Deployment。在每个部署之上创建一个Service。然后从数据消费者可以指向kubernetes提供的内部dns服务。

    假设您的数据摄取服务是:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
    spec:
      selector:
        app: ingestion
      ports:
        - protocol: TCP
          port: 80
          targetPort: 9090
    

    你可以使用myservice.default.svc.cluster.local的dns。

    【讨论】:

    • 如果我有一个 pod 而不是部署,它会不起作用吗?在 pod2 中,在环境变量中——我应该写 my-service 而不是 IPadd:pv ?但这不起作用
    • 是的,Pod 规范还有一个可选的子域字段,可用于指定其子域。例如,在命名空间“my-namespace”中,主机名设置为“foo”,子域设置为“bar”的 Pod 将具有完全限定域名(FQDN)“foo.bar.my-namespace.svc”。集群域.example”。看到这个kubernetes.io/docs/concepts/services-networking/dns-pod-service/…
    猜你喜欢
    • 1970-01-01
    • 2019-01-21
    • 2016-04-03
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多