【发布时间】:2020-02-15 11:16:29
【问题描述】:
我对使用 npx create-react-app react-app 创建的简单 React 应用程序有疑问。在 k8s 上部署后,我得到了这个:
Uncaught SyntaxError: Unexpected token '<'
但是,如果我想 kubectl port-forward 到 pod 并在 localhost:3000 处查看应用程序(容器的 pod 位于 3000,集群 ip 服务侦听 3000 并转发到 3000)完全没有问题。
入口路由看起来不错,因为我可以访问其他服务以在集群内工作,但不能访问应用程序。一些帮助将不胜感激。
部署yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: react-app-deployment
# namespace: gitlab-managed-apps
spec:
replicas: 1
selector:
matchLabels:
component: react-app
template:
metadata:
labels:
component: react-app
spec:
imagePullSecrets:
- name: simpleweb-token-namespace
containers:
- name: react-app
image: registry.gitlab.com/mttlong/sample/react-app
env:
- name: "PORT"
value: "3000"
ports:
- containerPort: 3000
集群ip服务:
apiVersion: v1
kind: Service
metadata:
name: react-app-cluster-ip-service
spec:
type: ClusterIP
selector:
component: react-app
ports:
- port: 3000
targetPort: 3000
Dockerfile:
FROM node:10.15.3-alpine as builder
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx
EXPOSE 3000
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html
入口服务:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: orion-ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: horizon.zeezum.com
http:
paths:
- path: /
backend:
serviceName: react-app-cluster-ip-service
servicePort: 3000
- path: /api(/|$)(.*)
backend:
serviceName: simple-api-nodeport-service
servicePort: 3050
【问题讨论】:
-
能否提供部署yaml
-
你能把整个文本放到错误中吗?
-
资源解释为样式表,但使用 MIME 类型 text/html 传输:“horizon.zeezum.com/static/css/main.d1b05096.chunk.css”。 2.964cd682.chunk.js:1 Uncaught SyntaxError: Unexpected token '
-
您好,我也遇到了同样的问题,请问您找到解决方案了吗?还是根本原因?
-
不幸的是,没有。问题仍然存在。
标签: reactjs kubernetes