[英]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.