Question

How to connect two NodeJS backend pods in kubernetes using axios

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

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi, I have finally resolved the issue. By doing that it was showing me an EINVAL error. I had to put http before

Thank you !

Bobby Iliev
Site Moderator
Site Moderator badge
August 2, 2020

Hi there @cheikhseck980,

What happens when you try to use the service name itself? For example if your pod A need to get data from pod B, what is the result when you do axios.get(podB-cluster-ip-service/endpoint) from pod A?

Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more