Report this

What is the reason for this report?

How to connect two NodeJS backend pods in kubernetes using axios

Posted on August 2, 2020

Hi, I would like to connect two backend pods with axios For each pod I have a deployment.yaml file and a cluster-ip-service.yaml file. One of the pod need to get data from the other pod via axios. I use Ingress for traffic When I call

axios.get(my-cluster-ip-service/endpoint) 

it can’t resolve my-cluster-ip-service

The first pod deployment

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: podA-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: podA
  template:
    metadata:
      labels:
        component: podA
    spec:
      containers:
        - name: podA
          image: podA/img
          ports:
            - containerPort: 5000


The first pod service

apiVersion: v1
kind: Service
metadata:
  name: podA-cluster-ip-service
spec:
  type: ClusterIP
  ports: 
    - port: 5000
      targetPort: 5000 
 
  selector:
    component: podA


The second pod deployment

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: podB-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: podB
     
  template:
    metadata:
      labels:
        component: podB

    spec:
      containers:
        - name: podB
          image: podB/img2
          ports:
            - containerPort: 5000

         

The second pod service

apiVersion: v1
kind: Service
metadata:
  name: podB-cluster-ip-service
spec:
  type: ClusterIP
  ports: 
    - port: 5000
      targetPort: 5000 
  selector:
    component: podB

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.