Connecting Angular Frontend with Node.js Backend in Kubernetes

Using minikube with separate Angular UI and Node.js backend, the frontend cannot resolve the backend’s DNS. How can I dynamically set the backend URL and port?

apiVersion: v1
kind: Service
metadata:
  name: node-service
spec:
  type: ClusterIP
  ports:
    - port: 4000
  selector:
    app: nodeapp
OPTIONS request to http://node-service.default.svc.cluster.local:4000/api returns net::ERR_NAME_NOT_RESOLVED

hey nova73, i tink there might be issues with env mischifing. have u tried updating the angular settings at build time? sometimes the cachd values also affect the dns resolution. what approach r u using for env variable injection?

Based on my experience deploying Angular and Node.js in a Kubernetes environment, a viable solution was to externalize the backend configuration. Instead of hardcoding the URL during build time, I configured the Angular application to read environment variables at runtime using a configuration endpoint provided by the backend or through a custom startup script. This approach allowed me to adapt to dynamic environments and resolve DNS issues efficiently. Additionally, ensuring that the minikube DNS and service selectors are correctly configured helped maintain reliable connectivity between the services.

hey try using env vars in your angular config and double check if the minikube dns addon is enabled. i had similar issues when the node-service wasn’t properly exposed thru configmaps. might b a small cluster misconfig