简体   繁体   English

将本地 PC 上运行的 React Client 连接到 Azure 上的 Kube.netes 集群

[英]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.

相关问题 如何从同一网络的另一台 PC 连接到本地 React 应用程序? - How to connect to local react app from another PC from same network? 通过 ingress-nginx 作为代理从在 localhost 上运行的 react 应用程序访问 Kubernetes 集群 - Accessing Kubernetes Cluster through ingress-nginx as proxy from react app running on localhost React 没有命中 kubernetes 集群上的 django api - React is not hitting django apis on kubernetes cluster ipfs 节点无法连接到我在本地主机上运行的 react 应用程序 - Ipfs node won't connect to my react app running on local host 如何将 react pwa 部署到 IBM Cloud Kubernetes 集群? - How do I deploy a react pwa to IBM Cloud Kubernetes cluster? “无效的主机头”Kubernetes 集群在数字海洋与反应 - “Invalid Host header” Kubernetes cluster on Digital Ocean with React 在服务器上反应渲染并在客户端上运行 - react rendering on server and running on client 无法使用 kubernetes 连接到 react js 应用程序的 api 服务器? - Unable to connect to api server of react js app using kubernetes? Apollo Client React 和本地状态最佳实践 - Apollo Client React and local state best practices 流星本地客户端集合与React组件 - Meteor local client collection with React components
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM