简体   繁体   中英

REST api call between two pods in minikube

I'm running a REACT application on top of a minikube cluster which includes frontend and the backend in the same namespace default . When frontend send a request to backend, request doesn't reach to the backend. Load balancing happens via ingress-nginx .

service for front end...

apiVersion: v1
kind: Service
metadata:
  name: frontend-service
spec:
  type: ClusterIP
  selector:
    app: frontend-panel
  ports:
  - port: 3000
    targetPort: 3000

Service for backend

apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  type: ClusterIP
  selector:
    app: backend-panel
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080

Front end is a react application which calls different services which run in side of the same minikube cluster.., Configfile of react.

window.config = {
  backend: {
    backend_service: "http://backend-service:8080/"
  }
}

Result of kubectl describe svc backend-service .

Name:              backend-service
Namespace:         default
Labels:            <none>
Annotations:       Selector:  app=backend-panel
Type:              ClusterIP
IP:                10.106.135.236
Port:              <unset>  8080/TCP
TargetPort:        8080/TCP
Endpoints:         172.17.0.10:8080
Session Affinity:  None
Events:            <none>

Other than "http://backend-service:8080/" I tried "http://backend-service.default.svc.cluster.local:8080/" . But without failing the request it hangs for a longtime.

Service looks good because it has got POD IP and PORT as Endpoints . Verify if you are able to access the pod directly via PODIP and PORT using curl 172.17.0.10:8080 from another pod in the cluster. If that does not work then there could be two reasons

  1. Application is not listening on port 8080 . Just specifying containerPort: 8080 in pod yaml does not make the application listen on port 8080 .

  2. Application is listening on 127.0.0.1 instead of 0.0.0.0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM