Kubernetes Ingress deploy Angular assets (image) doesn't show

4/19/2019

I use Docker to package the Angular project (container use Nginx). When running on Docker, the images shows up ok, but when deploying to Kubernetes, using Ingress, all images in the assets folder do not appear.

Content-Type running on Docker. It's OK:

Link Image

But when running on Kubernetes. Content type always is text/html:

Link Image

Config Ingress Kubernetes. Service name ssite.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: abc-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "swing-static-ip"
    ingress.kubernetes.io/force-ssl-redirect: "true"
    ingress.gcp.kubernetes.io/pre-shared-cert: "abc,xyz"
spec:
  rules:
  - host: abc.com
    http:
      paths:
      - backend:
          serviceName: sservice
          servicePort: 8000
  - host: xyz.com
    http:
      paths:
      - path : /
        backend:
          serviceName: ssite
          servicePort: 80
      - path : /*
        backend:
          serviceName: ssite
          servicePort: 80
-- NguyenHung
angular
kubernetes

2 Answers

4/23/2019

In your nginx config set default_type directive

Defines the default MIME type of a response. Mapping of file name extensions to MIME types can be set with the types directive.

server {
   ...
   default_type text/html;

   location /assets/imgs {
      default_type image/png;
   }

   location /assets/imgs {
      default_type image/jpeg;
   }
}
-- A_Suh
Source: StackOverflow

4/19/2019

Try adding anotation :

are you using nginx ingress ?

nginx.ingress.kubernetes.io/rewrite-target: /
-- Harsh Manvar
Source: StackOverflow