1

I have a kubeadm cluster and i am trying to deploy to static websites using ingress (after installing the metalLB and nginx-ingress controller )

After deploying the ingress, i find that the ingress don't load the website assets (the html file only) Please any help !

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: ingress-test
spec:
  ingressClassName: nginx
  rules:
  - host: k8s.example.k8s
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-svc
            port:
              number: 80
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-svc
            port:
              number: 80

  • check your path setup, open browser console and check what path failing and throwing 404 error. – Harsh Manvar Jun 27 '22 at 16:05
  • i find a lot of output like this on the console `The stylesheet http://k8s.example.k8s/gym/css/bootstrap.min.css was not loaded because its MIME type, “text/html”, is not “text/css”` – Mohamed Rafraf Jun 27 '22 at 16:17

1 Answers1

2

Make sure your routing working properly with ingress

Example and it's not 404 for css:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: service
              servicePort: 3000
          - path: /api/?(.*)
            backend:
              serviceName: service
              servicePort: 5000

Read more at : https://github.com/kubernetes/ingress-nginx/issues/2557

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102