Kubernetes: ERR_NAME_NOT_RESOLVED

2/25/2019

I have deployed a mongo db, Spring Boot BE, Angular app within GKE. My FE service is a load balancer, it needs to connect with my BE to get data but I'm getting an console error in my browser: GET http://contactbe.default.svc.cluster.local/contacts net::ERR_NAME_NOT_RESOLVED. My FE needs to consume /contacts endpoint to get data. I'm using DNS from my BE service (contactbe.default.svc.cluster.local) within my Angular app. It is my yml file that I used to create my deployment:

apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    run: mongo
spec:
  type: NodePort
  ports:
  - port: 27017
    targetPort: 27017
    protocol: TCP
  selector:
    run: mongo
---
apiVersion: apps/v1beta1
kind: Deployment
metadata: 
  name: mongo
spec:
  template:
    metadata:
      labels:
        run: mongo
    spec:
      containers:
      - name: mongo
        image: mongo
        ports:
        - containerPort: 27017
---        
apiVersion: v1
kind: Service
metadata:
  name: contactbe
  labels:
    app: contactbe
spec:
  type: NodePort 
  ports:
  - port: 8181
    targetPort: 8181
    protocol: TCP
  selector:
    app: contactbe
---
apiVersion: apps/v1beta1
kind: Deployment
metadata: 
  name: contactbe
spec:
  template:
    metadata:
      labels:
        app: contactbe
    spec:
      containers:
      - name: contactbe
        image: glgelopfalcon/k8s_contactbe:latest
        ports:
        - containerPort: 8181
---
apiVersion: apps/v1beta1 # for versions before 1.9.0 use apps/v1beta2 
kind: Deployment 
metadata: 
  name: angular-deployment 
spec: 
  selector: 
    matchLabels: 
      app: angular 
  replicas: 2 # tells deployment to run 2 pods matching the template 
  template: 
    metadata: 
      labels: 
        app: angular 
    spec: 
      containers: 
      - name: angular 
        image: glgelopfalcon/my-angular-app:latest 
        ports: 
        - containerPort: 80
--- 
# https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service  
kind: Service 
apiVersion: v1 
metadata: 
  name: angular-service 
spec: 
  selector: 
    app: angular 
  ports: 
  - port: 80
    targetPort: 80
    protocol: TCP
  type: LoadBalancer 

I googled a lot but I still have not found how to solve this problem. I would appreciate if someone could give a hand.

Console error

-- user3380193
angular
google-kubernetes-engine
kube-dns
kubernetes
spring-boot

3 Answers

2/25/2019

check for your load balancer having open port 27017 as your sending request to port 27017

otherwise you can change service node port to 80 and target port will be same

-- Harsh Manvar
Source: StackOverflow

2/28/2019

I found a solution. I changed the kind of service from my Backend. Instead of ClusterIP I'm using a Load balancer, it works as expected

-- user3380193
Source: StackOverflow

2/25/2019

port# is missing in the URL. try below

contactbe.default.svc.cluster.local:8181/contacts
-- P Ekambaram
Source: StackOverflow