Creating a default NextJS typescript app with npx create-next-app@latest --ts .
"next": "12.1.6",
"react": "18.1.0",
"react-dom": "18.1.0"
and then a simple Dockerfile deployed to kubernetes minikube and then minikube tunnel to access the port
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN yarn install
COPY . .
CMD ["yarn", "dev"]
Shows a blank page with the following errors in the console when running in browser
Uncaught SyntaxError: Unexpected token '<'
However running the same image via docker run, in non k8s, works fine. I have had a look at the HTML for absolute paths as suggested in other threads and see that the path points to
http://myhost.com/_next/static/chunks/react-refresh.js?ts=1654439747173
When hovering over src
<div id="__next">
<script src="/_next/static/chunks/react-refresh.js?ts=1654439747173"></script>
deployment.yaml and ingress files
apiVersion: apps/v1
kind: Deployment
metadata:
name: front-depl
spec:
replicas: 1
selector:
matchLabels:
app: front
template:
metadata:
labels:
app: front
spec:
containers:
- name: front
imagePullPolicy: Never
image: mine/front:latest
resources:
limits:
memory: 512Mi
cpu: "1"
---
apiVersion: v1
kind: Service
metadata:
name: front-service
spec:
selector:
app: front
ports:
- name: front
protocol: TCP
port: 3000
targetPort: 3000
// ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: myhost.com
http:
paths:
- path: /?(.*)
pathType: Prefix
backend:
service:
name: front-service
port:
number: 3000
Any idea on getting it running in kubernetes?
I got it working by updating the ingress rewrite target
changing
nginx.ingress.kubernetes.io/rewrite-target: /$2
to
nginx.ingress.kubernetes.io/rewrite-target: /$1
and the path to
path: /(.*)