Getting error when I run Strapi in Kubernetes

System Information
  • Strapi Version: 4.1.2
  • Operating System: Kubernetes Cluster
  • Database: postgres
  • Node Version: 14.19.0
  • NPM Version: na
  • Yarn Version: 1.22.17

I am running Strapi in a Kubernetes cluster containing a postgres deployment with persistent volume (cluster ip) | strapi deployment (cluster ip) | nginx ingress

I am able to connect to my Strapi deployment using IP/admin and I get the Strapi registration screen and register, but when I try to login I get and error message saying “Error: an error occurred” with no other lead, the progress indicator just keeps spinning forever, even when check the Strapi pod logs there is no 404 error or anything like that, all http statuses are 200, but for some reason I am still getting the error despite trying everything, below you’ll find my Ingreres/Postgres/Strapi configuration

PS: the same configuration is working locally using NodePort

Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: 'nginx'
spec:
  rules:
  - http:
      paths:
        - path: /admin
          pathType: Prefix
          backend:
            service:
              name: strapi-cluster-ip-service
              port:
                number: 1337

Postgres

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: postgres
  template:
    metadata:
       labels:
         component: postgres
    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data
              subPath: postgres
          env:
            - name: POSTGRES_DB
              value: strapi
            - name: POSTGRES_USER
              value: strapi
            - name: POSTGRES_PASSWORD
              value: <PASSWORD>

Strapi

apiVersion: apps/v1
kind: Deployment
metadata:
  name: strapi-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: strapi
  template:
    metadata:
       labels:
         component: strapi
    spec:
      containers:
        - name: strapi
          image: alexyib/strapi-generic:v1
          ports:
            - containerPort: 1337
          env:
            - name: DATABASE_CLIENT
              value: postgres
            - name: DATABASE_NAME
              value: strapi
            - name: DATABASE_HOST
              value: postgres-cluster-ip-service
            - name: DATABASE_PORT
              value: '5432'
            - name: DATABASE_USERNAME
              value: strapi
            - name: DATABASE_PASSWORD
              value: <PASSWORD>

alexyib/strapi-generic:v1 was created using the below Dockerfile

FROM node:14

ENV APP_HOME /usr/src/app
WORKDIR $APP_HOME
ADD ./package.json .
ADD ./yarn.lock .
RUN yarn install --frozen-lockfile

ADD . .

ENV NODE_ENV production
RUN yarn install

RUN yarn build

EXPOSE 1337

CMD ["yarn", "start"]

Any advise? Thank you in advance,
I will gladly provide any other configuration files needed but didn’t want this topic to become very long


1 Like

Hello @alexyib, how are you?
I’m struggling with the same problem. Have you figured out how to fix it? If so, could you share some info about how you have done it in your environment?

Thanks

Hello @nicklima , did you solve your problem at the end? I would be extremely grateful if you could share your Kubernetes configuration because I have been trying to set Strapi up without any success.

Thank you very much in advance and regards

Hi @javierguzman. We are working on it yet.
I just asked my friend on the DEVOPS team to take a look at this post and share his experiences on this issue here to help you and others.

Thanks @nicklima. I have actually managed to solve it. In my personal case, it was not working because I completely forgot to update the DNS of my domain to point out my cluster. i.e. www.strapibackendwhatsoever.mydomain.com pointing to my cluster ip

1 Like