我已经在GKE中部署了mongo数据库,Spring Boot BE,Angular应用程序。我的FE服务是一个负载平衡器,它需要与我的BE连接才能获取数据,但是我的浏览器出现控制台错误: GET http://contactbe.default.svc.cluster.local/contacts net :: ERR_NAME_NOT_RESOLVED 。我的FE需要使用 / contacts 端点来获取数据。我正在Angular应用程序中通过BE服务(contactbe.default.svc.cluster.local)使用DNS。这是我用来创建部署的yml文件:
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上搜索了很多,但仍然没有找到如何解决此问题的方法。如果有人可以伸出援手,我将不胜感激。
答案 0 :(得分:0)
检查您的负载均衡器是否已打开端口27017作为向端口27017的发送请求
否则,您可以将服务节点端口更改为80,并且目标端口将相同
答案 1 :(得分:0)
端口号。尝试以下
contactbe.default.svc.cluster.local:8181/contacts
答案 2 :(得分:0)
我找到了解决方案。我从后端更改了服务类型。我使用的是负载均衡器,而不是ClusterIP,它可以按预期工作