【问题标题】:Pod to Pod communication using DNS names使用 DNS 名称的 Pod 到 Pod 通信
【发布时间】:2020-07-24 19:44:44
【问题描述】:

在我的 Kubernetes 集群上,我有几个可以相互通信的 pod。它们分别部署 我创建了一个名为 my-service 的无头服务,它针对所有 pod。

apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: default
spec:
  clusterIP: None
  ports:
  - name: test1
    port: 111
    protocol: TCP
    targetPort: 111
  - name: test2
    port: 222
    protocol: TCP
    targetPort: 222
  publishNotReadyAddresses: true
  selector:
    app: "my-app"
  type: ClusterIP

每个 pod 都暴露两个端口:111 和 222

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: "my-app"
  name: my-service-6c44bdf68c-q6jdq
  namespace: default
spec:
  containers:
  - image: my-image
    name: my-app
    ports:
    - containerPort: 111
      name: test1
      protocol: TCP
    - containerPort: 222
      name: test1
      protocol: TCP

当我执行nslookup on my-service.default.svc.cluster.local 时,我确实可以看到我所有的 pod。

我还为每个 pod 分配了单独的主机名和 subdomain: my-service。现在每个 Pod 都有一个单独的 DNS A 记录,例如:<hostname>.my-service.default.svc.cluster.local。到目前为止,一切都很好。但是当我尝试使用域(和端口)<hostname>.my-service.default.svc.cluster.local:111 访问 pod(从另一个容器)时,我得到了“连接被拒绝”。我怎样才能使这项工作?我错过了什么吗?

【问题讨论】:

  • 您如何尝试从其他 pod 访问服务,我的意思是 curl、ping 或其他?
  • Ping 有效。我正在尝试 HTTP 连接
  • nslookup 对 .my-service... 的 IP 说了什么?
  • 它提供了正确的 pod IP
  • 这意味着 dns 工作正常。你确定有东西在监听这些端口吗?

标签: networking kubernetes kubernetes-pod


【解决方案1】:

问题的最可能原因是您尝试访问服务的方式。如果您检查响应端口 111 的内容,它将起作用。

例如,在不侦听的端口上建立 http 连接将导致 Connection Refused。

根据您的服务尝试 ping 或 telnet。

【讨论】:

    猜你喜欢
    • 2019-02-06
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多