简体   繁体   English

为什么在 Kube.netes 集群中部署时无法通过入口在浏览器中打开 React web 应用程序

[英]Why can I not open a React web app in a browser through an ingress when deploying it in a Kubernetes cluster

I have a very simple React web app (using Argon Dashboard Pro Template) deployed in a Kube.netes cluster.我在 Kube.netes 集群中部署了一个非常简单的 React web 应用程序(使用 Argon Dashboard Pro 模板)。 The Docker image of it works locally as well as in the cluster when exposing it via nodeport.当通过节点端口公开它时,它的 Docker 图像在本地和集群中工作。 But exposing it via NGINX ingress doesn't work, although the ingress itself is tested for other services and applications which expose REST endpoints.但是通过 NGINX 入口暴露它是行不通的,尽管入口本身已经针对暴露 REST 端点的其他服务和应用程序进行了测试。 The content of the web page is not built correctly, because some js files are not found, although this is the case when they are exposed via nodeport. web页面的内容没有正确构建,因为有些js文件没有找到,虽然通过nodeport暴露出来是这样的。

Kube.netes Deployment: Kube.netes 部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: react-deployment
  namespace: support
  labels:
    app: react
    stage: dev
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: react
    spec:
      containers:
        - name: react
          image: fmaus/react-test:argon
          ports:
            - containerPort: 3000
              name: react-port
          imagePullPolicy: Always
      restartPolicy: Always
  selector:
    matchLabels:
      app: react

Kube.netes Ingress Kube.netes 入口

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: react-ingress
  namespace: support
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header Accept-Encoding "";
      more_set_headers "Content-Type: text/javascript; charset=UTF-8";
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /test(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: react-service
            port:
              number: 3000

Kube.netes Service: Kube.netes 服务:

apiVersion: v1
kind: Service
metadata:
  name: "react-service"
  namespace: support
spec:
  selector:
    app: "react"
  ports:
    - port: 3000
  type: ClusterIP

This Code can also be found in my GitHub Repository: https://github.com/fmaus/react-kube.netes-test此代码也可以在我的 GitHub 存储库中找到: https://github.com/fmaus/react-kube.netes-test

To reproduce the problem, just apply these Kube.netes resources to a cluster and try to reach the web app through a browser via ingress (http://host/subpath).要重现该问题,只需将这些 Kube.netes 资源应用到集群并尝试通过浏览器通过入口(http://host/subpath)访问 web 应用程序。 I have the resources deployed here: http://c105-164.cloud.gwdg.de:31600/test The error messages can be visited in the console of the browser (F12 when using Firefox):我这里部署了资源: http://c105-164.cloud.gwdg.de:31600/test错误信息可以在浏览器的控制台访问(使用Firefox时F12):

Loading failed for the <script> with source “http://c105-164.cloud.gwdg.de:31600/static/js/bundle.js”. subpath:61:1
Loading failed for the <script> with source “http://c105-164.cloud.gwdg.de:31600/static/js/vendors~main.chunk.js”. subpath:61:1
Loading failed for the <script> with source “http://c105-164.cloud.gwdg.de:31600/static/js/main.chunk.js”.

I use Mozilla Firefox and the following NGINX ingress controller: https://kube.netes.github.io/ingress-nginx/我使用 Mozilla Firefox 和以下 NGINX 入口 controller: https://kube.netes.github.io/ingress-nginx/

I think you have two issues in place here:我认为你在这里有两个问题:

For example例如

<script src="/static/js/bundle.js"></script><script src="/static/js/vendors~main.chunk.js"></script><script src="/static/js/main.chunk.js"></script></body>

Needs to load the bundle from /subpath/static/js/bundle.js since it is an absolute link.需要从 /subpath/static/js/bundle.js 加载包,因为它是一个绝对链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 ingress-nginx 作为代理从在 localhost 上运行的 react 应用程序访问 Kubernetes 集群 - Accessing Kubernetes Cluster through ingress-nginx as proxy from react app running on localhost 对 Kubernetes Ingress 做出反应 - React on Kubernetes Ingress 通过 GitLab 在 Firebase 上部署 React 应用程序时出现“eslint:权限被拒绝” - "eslint: Permission denied" when deploying React app on Firebase through GitLab 反应应用程序无法通过 kubernetes 访问 - react app not accessibile through kubernetes 当我将 React 包放入 Html 脚本标签并通过浏览器打开 html 时,它不起作用 - React bundle doesnt work when I put it inside an Html script tag and open the html through a browser 为什么需要提供React构建? 为什么我不能在浏览器中打开它? - Why does a React build need to be served? Why can't I just open it in the browser? 在 github 页面上部署 React 应用程序时,如何将我的源代码上传到 github - How can I upload my source code to github when deploying a React app on github pages 使用两个任务部署到 ECS fargate 集群时如何配置 React 应用程序获取端口 - How to configure port of React app fetch when deploying to ECS fargate cluster with two tasks Kubernetes(minikube) + React 前端 + .netcore api + 集群 IP 服务 + ingress + net::ERR_NAME_NOT_RESOLVED - Kubernetes(minikube) + React Frontend + .netcore api + Cluster IP service + ingress + net::ERR_NAME_NOT_RESOLVED 通过.netlify 部署 React 应用程序时遇到问题 - trouble deploying react app through netlify
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM