Kubernetes:ERR_NAME_NOT_RESOLVED [英] Kubernetes: ERR_NAME_NOT_RESOLVED
问题描述
我已经在GKE中部署了mongo数据库,Spring Boot BE和Angular应用程序.我的FE服务是一个负载平衡器,它需要与我的BE连接才能获取数据,但是在浏览器中出现控制台错误: GET
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
我在Google上搜索了很多,但仍然没有找到如何解决此问题的方法.如果有人可以伸出援手,我将不胜感激.
I googled a lot but I still have not found how to solve this problem. I would appreciate if someone could give a hand.
推荐答案
我找到了解决方案.我从后端更改了服务类型.我使用的是负载均衡器,而不是ClusterIP,它可以按预期工作
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
这篇关于Kubernetes:ERR_NAME_NOT_RESOLVED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!