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

6/21/2019

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).

When i write the code for pod A, which address should i use for identify pod B ?

-- Marco
http
kubernetes
minikube

1 Answer

6/21/2019

You need to expose Pod-B as Services.

For Pod-B assuming your Pod Definition looks something it as service something like this:

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 i.e Service, define it something like this

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