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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.