[英]Connect React Client running on local PC to Kubernetes Cluster on Azure
I have 2 deployments + services running on Azure: react client and nodejs auth.我有 2 个部署 + 服务在 Azure 上运行:react client 和 nodejs auth。 I have registered a public IP on Azure which I added to my windows host file (= myexample.com
).我已经在 Azure 上注册了一个公共 IP,我将其添加到我的 windows 主机文件(= myexample.com
)。 Typing the URL in the browser, the client opens and requests go to auth service as expected.在浏览器中键入 URL,客户端打开并请求 go 以按预期进行身份验证服务。
Now I want to run the client locally (with npm start
) but connect to auth service still running on Azure.现在我想在本地运行客户端(使用npm start
)但连接到仍在 Azure 上运行的身份验证服务。
I removed the client from the cloud deployment (= the deployment+the service) and use the domain (= myexample.cloud
) as the base URL in my axios client in my React client.我从云部署(=部署+服务)中删除了客户端,并在我的 React 客户端的 axios 客户端中使用域(= myexample.cloud
)作为基础 URL。 To confirm, on Azure my ingress-nginx-controller of type Load_Balancer shows the aforementioned public IP as its external IP plus ports 80:30819/TCP,443:31077/TCP.为了确认,在 Azure 上,我的 Load_Balancer 类型的 ingress-nginx-controller 将上述公共 IP 显示为其外部 IP 加上端口 80:30819/TCP,443:31077/TCP。 When I ran the Client locally, it shows the correct request URL ( http://myexample.cloud/api/users/signin
) but I get a 403 Forbidden
answer.当我在本地运行客户端时,它显示正确的请求 URL ( http://myexample.cloud/api/users/signin
) 但我得到一个403 Forbidden
答案。
What am I missing?我错过了什么? I should be able to connect to my cloud service by using the public IP?我应该能够使用公共 IP 连接到我的云服务吗? There error is caused by my client because Azure is not putting road blocks in place.错误是由我的客户引起的,因为 Azure 没有设置路障。 I mean it is a pubic IP, correct?我的意思是它是公共 IP,对吗?
Update 1更新 1
Just to clarify, the 403 Forbidden
is not caused by me trying to sign in with incorrect credentials.澄清一下, 403 Forbidden
不是我尝试使用不正确的凭据登录造成的。 I have another api/users/health-ckeck
route that is giving me the same error我有另一个api/users/health-ckeck
路由给我同样的错误
My cloud ingress deployment.我的云入口部署。 I have also tried to remove the client part (last 7 lines) to no effect.我也曾尝试删除客户端部分(最后 7 行)但没有效果。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: myexample.cloud
http:
paths:
- path: /api/users/?(.*)
pathType: Prefix
backend:
service:
name: auth-srv
port:
number: 3000
- path: /
pathType: Prefix
backend:
service:
name: client-srv
port:
number: 3000
my client cloud deployment+service that worked when client was running in cloud当客户端在云中运行时,我的客户端云部署+服务有效
apiVersion: apps/v1
kind: Deployment
metadata:
name: client
spec:
replicas: 1
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: client
---
apiVersion: v1
kind: Service
metadata:
name: client
spec:
selector:
app: client
ports:
- name: client
protocol: TCP
port: 3000
targetPort: 3000
my auth deployment + service我的授权部署+服务
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: auth
apiVersion: v1
kind: Service
metadata:
name: auth
spec:
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 3000
targetPort: 3000
The problem was actually CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'
but my browser did not tell me.问题实际上是CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'
,但我的浏览器没有告诉我。 After switching from Chrome to Firefox, the problem became apperant.从 Chrome 切换到 Firefox 后,问题变得明显。 I had to add annotations to my ingress controller as described here: express + socket.io + kube.netes Access-Control-Allow-Origin' header我必须按照此处所述向我的入口 controller 添加注释: express + socket.io + kube.netes Access-Control-Allow-Origin' header
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.