Home > Back-end >  Externally exposed frontend service (NodePort) can't communicate with internally available back
Externally exposed frontend service (NodePort) can't communicate with internally available back

Time:11-30

The app consists of 3 components: frontend, backend and Redis. The frontend communicates only with the backend, the Redis service communicates only with the backend service. All pods run correctly, at least logs don't show anything disturbing.

The backend is built with NodeJS/ExpressJS, the frontend: with React.

Services are configured in the following way:

frontend:

apiVersion: v1
kind: Service
metadata:
  name: plg-frontend
  labels:
    name: plg-frontend-service
    app: playground-app
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30010
    protocol: TCP
  selector:
    name: plg-frontend-pod
    app: playground-app

backend:

apiVersion: v1
kind: Service
metadata:
  name: plg-backend
  labels:
    name: plg-backend-service
    app: playground-app
spec:
  ports:
  - port: 4000
    targetPort: 5011
  selector:
    name: plg-backend-pod
    app: playground-app

All services run correctly:

kubectl get svc
NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
plg-backend       ClusterIP   10.233.23.12   <none>        4000/TCP       2d3h
plg-frontend      NodePort    10.233.63.20   <none>        80:30010/TCP   2d3h
redis             ClusterIP   10.233.59.37   <none>        6379/TCP       2d3h

At the moment, the frontend running on host's IP, let's say http://10.11.12.13:30010, tries to call the backend's internal endpoint, so 10.233.23.12:5011 (the backend's targetPort). Connection times out. Should I expose the backend service to become NodePort to be accessible?

CodePudding user response:

No need to expose using NodePort unless you intend to let the backend service accessible on the host network. Your frontend should be calling 10.233.23.12:4000, not 5011 which is the backing pods listening on.

  • Related