Kubernetes: ERR_NAME_NOT_RESOLVED

戏子无情 提交于 2020-05-13 07:40:08

问题


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


回答1:


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




回答2:


port# is missing in the URL. try below

contactbe.default.svc.cluster.local:8181/contacts



回答3:


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



来源:https://stackoverflow.com/questions/54858192/kubernetes-err-name-not-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!