Good day all,
I have a small node.js program that gets it’s images from the default public directory. When I expose it using a service of type NodePort the applications is accesibPreformatted textle and shows it’s images. When I use a nginx ingress deployed using a daemonset I can access the application but none of my images are shown.
The ingress rules used are:
> apiVersion: extensions/v1beta1
> kind: Ingress
> metadata:
> name: visitor
> annotations:
> nginx.ingress.kubernetes.io/rewrite-target: /$1
> nginx.ingress.kubernetes.io/ssl-redirect: “false”
> kubernetes.io/ingress.class: visitor
> spec:
> rules:
> - http:
> paths:
> - path: /hello/?(.*)
> backend:
> serviceName: visitor-hello
> servicePort: 8080
The logs from the nginx controller
> 10.8.62.8 - [10.8.62.8] - - [17/Feb/2019:18:06:13 +0000] "GET /hello/ HTTP/1.1" 200 162 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36" 454 0.001 [visitor-visitor-hello-8080] 192.168.3.196:8080 162 0.001 200 8afd95c4d2e13c73dade53370c8c9aed
> 10.8.62.8 - [10.8.62.8] - - [17/Feb/2019:18:06:13 +0000] "GET /hello.svg HTTP/1.1" 404 143 "http://kub14n04:30100/hello/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36" 342 0.001 [visitor-visitor-hello-8080] 192.168.3.196:8080 143 0.001 404 f43b075fcc5d8ba73ed8c04496d94af7
The relevant nodejs code
> app.use(express.static('public')) ;
>
> res.send('<img src="/roxit.png" width=200px><H1>Hello World!</H1><br>Serving you from '+hostname+' <br>You are visitor: #'+visitorCount+' and coming from '+visitorAddr+'<br>') ;
> res.end() ;
My question:
How can I setup the ingress rules in such a way that the images, js etc are becoming ‘visible’ in my nodejs application?
I will document the issue and the solution for others.
Kind regards,
Pascal van Dam