简体   繁体   English

Pod 到 Pod 通信在 kubernetes 中不起作用

[英]Pod to Pod communication is not working in kubernetes

I am using Spring Boot to create REST API and that access MongoDB on load time.我正在使用 Spring Boot 创建 REST API 并在加载时访问 MongoDB。 I am making one deployment & service for REST API and one deployment and service for mongodb.我正在为 REST API 制作一项部署和服务,为 mongodb 制作一项部署和服务。

But my REST API pod is breaking and not coming up as on load time it looks for mongodb service but it is not able to ping that host.但是我的 REST API pod 坏了,在加载时没有出现,它寻找 mongodb 服务,但它无法 ping 那个主机。

I have exposed mongodb as a service and also REST API as a service.我已将 mongodb 作为服务公开,并将 REST API 作为服务公开。 REST API is exposed as NodePort and mongodb is exposed as ClusreIP. REST API 作为 NodePort 公开,mongodb 作为 ClusreIP 公开。

Everything i tried but no solution.我尝试过的一切,但没有解决方案。

===================================MongoDB deployment======================== ================================== MongoDB部署============ ============

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: tech-hunt-mongodb
spec:
  replicas: 1
  template:
    metadata:
      name: tech-hunt-mongodb
      labels:
        app: tech-hunt
        module: mongodb
    spec:
      containers:
      - image: <image>
        name: tech-hunt-mongodb
        ports:
        - containerPort: 27017

===================================MongoDB service======================== ================================== MongoDB 服务============ ============

apiVersion: v1
kind: Service
metadata:
  name: tech-hunt-mongodb
spec:
        #type: ClusterIP
  selector:
    app: tech-hunt
    module: mongodb
  ports:
  - port: 27017
    targetPort: 27017
    protocol: TCP
  clusterIP: None
    #nodePort: 30000
    #protocol: TCP

===========================REST API deployment================================ ==========================REST API 部署==================== ============

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: tech-hunt-api
spec:
  template:
    metadata:
      name: tech-hunt-api
      labels:
        app: tech-hunt
        module: rest-api    
    spec:
      containers:
      - image: <image>
        name: tech-hunt-api
        ports:
        - containerPort: 4000

===============================REST API service============================= ==============================REST API 服务================ ==============

apiVersion: v1
kind: Service
metadata:
  name: tech-hunt-api-client
spec:
  type: NodePort
  selector:
    app: tech-hunt
    module: rest-api-client
  ports:
  - port: 5000
    targetPort: 5000
    nodePort: 30010

clusterIP: None

is almost certainly not what you want to happen, as that places the burden of populating the Endpoints entirely on you -- or an external controller (the StatefulSet controllers are one such example).几乎肯定不是您想要发生的事情,因为这将填充Endpoints的负担完全放在您身上 - 或者外部控制器( StatefulSet控制器就是这样的一个例子)。

You'll have to delete, and then recreate, the tech-hunt-mongodb Service in order to change its clusterIP away from None over to an auto-populated value, but you should for sure do that first.您必须删除,然后重新创建tech-hunt-mongodb Service ,以便将其clusterIPNone更改为自动填充的值,但您应该首先这样做。

But my REST API pod is breaking and not coming up as on load time it looks for mongodb service but it is not able to ping that host.但是我的 REST API pod 坏了,在加载时没有出现,它寻找 mongodb 服务,但它无法 ping 那个主机。

As an FYI, you will never be able to "ping" a Service IP since those addresses are "fake";作为仅供参考,您将永远无法“ping” Service IP,因为这些地址是“假的”; only the tuple of Service IP and its traffic port (so, 27017 or 5000 in your two examples) will respond to any packets.只有Service IP 的元组及其流量端口(因此,在您的两个示例中为270175000 )将响应任何数据包。 You should use curl or nc to test connectivity, and not ping .您应该使用curlnc来测试连接性,而不是ping

I was using wrong mongodb image that was not giving access to the clients.我使用了错误的 mongodb 图像,该图像无法访问客户端。 So the created container was not pingable in neither mean via curl or so.因此,创建的容器无论如何都无法通过 curl 左右进行 ping 操作。 I am using NodePort and my rest API container is able to get response from mongodb container.我正在使用 NodePort,我的其余 API 容器能够从 mongodb 容器获得响应。

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

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