next js failing to route to page in a subfolder using default next js routing in a kubernetes cluster

8/10/2021

Am following a micro service tutorial , we are using docker and kubernetes for the services.one of the services is a client app in next,in the app we are using default next routing rules in which we have the pages in the pages folder,we made a subfolder in the page folder called auth and added another page signup.js. like so

folder structure

my yaml config file for the client service is like this

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: client
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
      - name: client
        image: dtemb965/client
---
apiVersion: v1
kind: Service
metadata: 
  name: client-srv
spec:
  selector:
    app: client
  ports:
    - name: client
      protocol: TCP
      port: 3000
      targetPort: 3000  

      

Ingress config file is like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations: 
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: ticketing.dev
      http:
        paths: 
          - path: /api/users/?(.*)
            backend:
              serviceName: auth-srv
              servicePort: 3000
          - path: /?(.*)
            backend:
              serviceName: client-srv
              servicePort: 3000
                   

and am using skaffold to manage running the services locally.The skaffold config file is like so

apiVersion: skaffold/v2alpha3
kind: Config
deploy:
  kubectl:
    manifests:
      - ./infra/k8s/*
build:
  local:
    push: false
  artifacts: 
    - image: dtemb965/auth
      context: auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts' 
            dest: .
    - image: dtemb965/client
      context: client
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: '**/*.js'
            dest: .       

when i run the app outside the container i.e without docker and kubernetes,all the routes are working just fine but when i run it in a kubernetes cluster and try to navigate to the page in the subfolder auth using the link https://ticketing.dev/auth/signup

am getting a 404 not found page. what could be wrong?

NOTE: all other pages outside the auth folder are working just fine either when run inside the cluster or outside

-- David Tembo
docker
javascript
kubernetes
next.js
skaffold

0 Answers