1

I have deployed angular frontend and python backend in kubernetes via microk8s as separate pods and they are running. I have given backend url as 'http://backend-service.default.svc.cluster.local:30007' in my angular file in order to link frontend with backend. But this is raising ERR_NAME_NOT_RESOLVED. Can someone help me in understanding the issue?

Also, I have a config file which specifies the ip's ports and other configurations in my backend. Do I need to make any changes(value of database host?, flask host?, ports? ) to that file before deploying t to kubernetes?

Shown below is my deployment and service files of angular and backend.

    apiVersion: v1
    kind: Service
    metadata:
     name: angular-service
    spec:
     type: NodePort
     selector:
      app: angular
     ports:
      - protocol: TCP
        nodePort: 30042
        targetPort: 4200
        port: 4200
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: angular-deployment
    labels:
      name: angular
    spec:
     replicas: 1
     selector:
      matchLabels:
        name: angular
     template:
       metadata:
         labels:
           name: angular
       spec:
         containers:
         - name: angular
           image: angular:local
           ports:
         - containerPort: 4200



  apiVersion: v1
  kind: Service
  metadata:
    name: backend-service
  spec:
    type:ClusterIP
    selector:
      name: backend
    ports:
      - protocol: TCP
        targetPort: 7000
        port: 7000
  ---
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: backend-deployment
     labels:
       name: backend
   spec:
     replicas: 1
     selector:
       matchLabels:
          name: backend
      template:
       metadata:
         labels:
           name: backend
       spec:
         containers:
         - name: backend
           image: flask:local
           ports:
           - containerPort: 7000
3
  • Name not resolved sound to me like DNS issues. Besides, your service is running on port 7000, not 30007. That's your node port. Commented Nov 12, 2019 at 8:53
  • while you deployed your angular application on kubernetes, it still runs in the client's browser, so make sure the name you use is known to the client. Commented Nov 12, 2019 at 8:54
  • Appears to be a DNS issue, try nslookup <service-url> and see if the resolution works in the first place. Commented Nov 12, 2019 at 8:59

1 Answer 1

2

Is your cluster in a healthy state ? DNS are resolved by object coredns in kube-system namespace.

In a classic way your angular app should show up your API Url in your browser so they must exposed and public. It is not your case and I have huge doubts about this. Expose us your app architecture?

Moreover if you expose your service though NodePort you must not use it for internal access because you never know the node you will access. When exose a service your apps need to use the port attribute (not the nodeport) to access pod generated in backend.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Germain, yes it is in a healthy state! Frontend pod is using NodePort and its accessible, rest is not communicating this way. I have gone through this kubernetes doc (kubernetes.io/docs/tasks/access-application-cluster/… ) and tried this but it didn't worked out!
If I change this url to http://<backend cluster ip>:port it works! but I can't dynamically pass the cluster ip to frontend
I am getting same issue ,perhaps we have to pass through proxy .
You have some solutions for reaching your app : (1) use ClusterIP, that I strongly recommend you! (2) create an internal service that collect the Node IP + Node Port of your service and give it to your application. This solution is dirty for you but is a needed turnaround in a fe situations like Kafka and Cassandra nodes managing (cf. Elassandra developed by friends of mine: github.com/strapdata/elassandra)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.