简体   繁体   English

如何使2个Pod在Kubernetes中相互通信?

[英]How can i make 2 pods communicate each other in kubernetes?

I'm using minikube, and i have 2 pods, pod A and pod B. I want that pod A make an http request to pod B, assuming that the two pods are in the same namespace (for example namepsace X). 我使用的是minikube,我有2个Pod,分别是Pod A和PodB。我希望Pod A向Pod B发出一个http请求,假设两个Pod在同一个命名空间中(例如namepsace X)。

When i write the code for pod A, which address should i use for identify pod B ? 当我为Pod A编写代码时,应使用哪个地址来标识Pod B?

You need to expose Pod-B as Services. 您需要将Pod-B公开为服务。

For Pod-B assuming your Pod Definition looks something it as service something like this: 对于Pod-B,假设您的Pod定义看起来像是服务,例如:

apiVersion: v1
kind: Pod
metadata:
  name: Pod-B
  labels:
    app: my-service
spec:
  containers:
  - name: nginx
    image: nginx:2.0.0
    ports:
    - containerPort: 80

To wrap your Pod-B with a higher level abstraction ie Service, define it something like this 要使用更高级别的抽象(即服务)包装Pod-B,请定义如下内容

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

暂无
暂无

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

相关问题 如何使客户端和服务器在 docker 中的用户定义网络中相互通信? - How to make a client and server communicate with each other in a user defined network in docker? 如何在heroku dyno中配置两个进程以相互通信 - How to configure two processes in a heroku dyno to communicate with each other 多个服务器端应用程序应如何相互“通信” - How should multiple server-side apps “communicate” with each other 如何使Android应用通过互联网与网络服务器通信? - How can I make an Android app communicate with a web server over the internet? 如何对 Kubernetes Pod 进行动态代理? - How to do Dynamic Proxying to Kubernetes Pods? 如何使用 rxjs 一个接一个地执行 2 个 http 调用,但不要等待第二个调用完成? - How can I execute 2 http calls after each other, but do not wait for the second one to complete, using rxjs? 在缓存所有图像,样式表和其他资源时,如何使我的HTML永不缓存? - How can I make my HTML to be never cached, while caching all images, stylesheets, and other resources? 我如何与用户的浏览器沟通它发出的 POST 请求是无副作用的? - How can I communicate to the user's browser that a POST request it made is side-effect-free? 2个不同的服务器如何在同一个“机器”中进行通信? - How can 2 different servers communicate in the same “machine”? GCP 函数不能互相调用 - GCP functions can't call each other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM