I’m working with a local minikube environment and have multiple services deployed. I need assistance in connecting my Angular frontend service to my Node.js backend service.
Here’s the current setup:
- The Angular application is hosted in its own service.
- The Node.js backend is also in a separate service and connects to a MongoDB service via DNS.
- Both services exist within the same Kubernetes cluster.
The challenge: My frontend application cannot resolve the backend service name through DNS. When making API calls, it doesn’t know how to locate the backend service.
Currently, the only workaround is to set the backend service to NodePort and manually specify the URL and port in the frontend configuration. This approach seems inefficient and unscalable.
I am aware that in a production scenario with a LoadBalancer service type, an external IP is assigned, but I would still face the challenge of having to rebuild the frontend image if the backend URL changes.
Backend service configuration:
apiVersion: v1
kind: Service
metadata:
name: backend
labels:
app: some-app
tier: backend
spec:
type: NodePort
ports:
- port: 3000
selector:
app: some-app
tier: backend
When attempting to access the backend using its fully qualified name, I receive the following error:
OPTIONS http://backend.default.svc.cluster.local:3000/signup/ net::ERR_NAME_NOT_RESOLVED
What’s the best way to manage communication between the frontend and backend services in Kubernetes without resorting to hardcoded URLs?