我正在尝试在本地minikube中部署应用程序。 当我启动minikube时,我可以连接到前端,但不能连接到后端。
以下是yaml文件
入口
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: client-cluster-ip-service
servicePort: 3000
- path: /api/
backend:
serviceName: server-cluster-ip-service
servicePort: 8080
UI部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-deployment
spec:
replicas: 1
selector:
matchLabels:
component: web
template:
metadata:
labels:
component: web
spec:
containers:
- name: client
image: registry.gitlab.com/test/test1/test2/app-UI
ports:
- containerPort: 3000
imagePullSecrets:
- name: gitlab-auth
UI服务
apiVersion: v1
# sets up networking in kubernetes cluster
kind: Service
metadata:
name: client-cluster-ip-service
spec:
selector:
component: web
ports:
- port: 3000
targetPort: 3000
后端部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 1
selector:
matchLabels:
component: server
template:
metadata:
labels:
component: server
spec:
containers:
- name: server
image: registry.gitlab.com/test1/test2/test3/test4-api
ports:
- containerPort: 8080
imagePullSecrets:
- name: gitlab-auth
后端服务
apiVersion: v1
kind: Service
metadata:
name: server-cluster-ip-service
spec:
type: ClusterIP
selector:
component: server
ports:
- port: 8080
targetPort: 8080
我在浏览器上不断出现以下错误
POST https://192.168.99.111/api/auth/login 404
dispatchXhrRequest @ xhr.js:155
xhrAdapter @ xhr.js:16
dispatchRequest @ dispatchRequest.js:49
Promise.then (async)
request @ Axios.js:55
Axios.<computed> @ Axios.js:74
wrap @ bind.js:11
(anonymous) @ LoginForm.tsx:34
callback @ createBaseForm.js:554
(anonymous) @ createBaseForm.js:579
validateFields @ createBaseForm.js:541
LoginForm.handleSubmit @ LoginForm.tsx:17
callCallback @ react-dom.development.js:147
invokeGuardedCallbackDev @ react-dom.development.js:196
invokeGuardedCallback @ react-dom.development.js:250
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:265
executeDispatch @ react-dom.development.js:571
executeDispatchesInOrder @ react-dom.development.js:596
executeDispatchesAndRelease @ react-dom.development.js:695
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:704
forEachAccumulated @ react-dom.development.js:676
runEventsInBatch @ react-dom.development.js:844
runExtractedEventsInBatch @ react-dom.development.js:852
handleTopLevel @ react-dom.development.js:5029
batchedUpdates$1 @ react-dom.development.js:21463
batchedUpdates @ react-dom.development.js:2247
dispatchEvent @ react-dom.development.js:5109
(anonymous) @ react-dom.development.js:21520
unstable_runWithPriority @ scheduler.development.js:255
interactiveUpdates$1 @ react-dom.development.js:21519
interactiveUpdates @ react-dom.development.js:2268
dispatchInteractiveEvent @ react-dom.development.js:5085
1)当我在不使用minikube的情况下运行该应用程序时,该应用程序运行正常。
2)当我使用minikube运行应用程序并点击https://192.168.99.111时,
前端很好。
3)一旦我尝试点击登录按钮并且应用程序尝试连接到
后端,出现上述错误。
4)由于某种原因,在运行时无法连接到后端
minikube和我一直在获取资源未找到错误。
192.168.99.111是minikube ip
我是kubernetes的新手,任何调试方面的帮助都将受到高度赞赏。
更新
我认为它与入口控制器有关 当我在Ingress Controller日志中看到它时,显示
192.168.99.1 - [192.168.99.1] - - [10/Jun/2019:00:07:58 +0000] "POST /api/auth/login HTTP/1.1" 404 19 "http://192.168.99.116/auth/login?redirect=/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" 520 0.001 [default-server-cluster-ip-service-8080] 172.17.0.8:8080 19 0.002 404 702298110b92307929f9817bb50c47ff
应该代替http://192.168.99.116/auth/login?redirect=/, http://192.168.99.116/api/auth/login?redirect=/
为什么/api
掉线了?
答案 0 :(得分:0)
您的入口配置没有问题。
您的后端应用程序具有将自身重定向到/auth/login
路径的规则,如果要添加前缀,则无法通过Ingress控制器解决。您必须配置后端API才能通过应用程序代码处理这些URL。
答案 1 :(得分:-1)
这就是nginx.ingress.kubernetes.io/rewrite-target: /
为您所做的。它将删除您的入口配置中的前缀。您可以删除此注释以将/api/
保留在路径中。
查看此内容:https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite