繁体   English   中英

使用 DNS 名称的 Pod 到 Pod 通信

[英]Pod to Pod communication using DNS names

在我的 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 记录,例如: <hostname>.my-service.default.svc.cluster.local 到目前为止,一切都很好。 但是,当我尝试使用域(和端口) <hostname>.my-service.default.svc.cluster.local:111访问 pod(从另一个容器)时,我得到了“连接被拒绝”。 我怎样才能使这项工作? 我错过了什么吗?

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

例如,在不监听它的端口上建立 http 连接将导致连接被拒绝。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM