Not able to access Spring Boot backend service from another service in Kubernetes

7/10/2019

I am new to Kubernetes and I am trying to create a simple front-end back-end application where front-end and back-end will have its own services. For some reason, I am not able to access back-end service by its name from front-end service.

Just because of simplicity, front-end service can be created like:
kubectl run curl --image=radial/busyboxplus:curl -i --tty

When I do a nslookup I get the following:

[ root@curl-66bdcf564-rbx2k:/ ]$ nslookup msgnc-travel
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      msgnc-travel
Address 1: 10.100.171.209 msgnc-travel.default.svc.cluster.local

Service is available by its name msgnc-travel, but when I try to do curl it:
curl msgnc-travel
it just keeps on waiting and no response is received. I have also tried
curl 10.100.171.209 and curl msgnc-travel.default.svc.cluster.local but I have the same behaviour

Any ideas why is this issue occurring?

I have successfully managed to do a "workaround" by using Ingress, but I am curious why can't I access my Spring Boot backend service directly just by providing its name?

deployment.yml looks like this:

apiVersion: apps/v1

kind: Deployment

metadata:
  name: msgnc-travel-deployment
  labels:
    name: msgnc-travel-deployment
    app: msgnc-travel-app

spec:
  template:
    metadata:
      name: msgnc-travel-pod
      labels:
        name: msgnc-travel-pod
        app: msgnc-travel-app

    spec:
      containers:
        - name: msgnc-travel
          image: bdjordjevic/msgnc-travel
          ports:
            - containerPort: 8080
  replicas: 1
  selector:
    matchExpressions:
      - {key: name, operator: In, values: [msgnc-travel-pod]}
      - {key: app, operator: In, values: [msgnc-travel-app]}

service.yml looks like this:

apiVersion: v1

kind: Service

metadata:
  name: msgnc-travel
  labels:
    name: msgnc-travel-service
    app: msgnc-travel-app

spec:
  ports:
    - port: 8080
      targetPort: 8080
  selector:
    name: msgnc-travel-pod
    app: msgnc-travel-app
-- Boban Djordjevic
kubernetes
microservices
spring-boot

1 Answer

7/10/2019

You are defining the service to listen at port 8080. So you are supposed to execute curl msgnc-travel:8080.

I tried running wget and this is the output I got:

wget msgnc-travel:8080
Connecting to msgnc-travel:8080 (10.98.81.45:8080)
wget: server returned error: HTTP/1.1 404 
-- Malathi
Source: StackOverflow