Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serving static files from ingress-nginx

I have a express web server with static files. Let's call this my express-deployment.

I'd like to use my ingress-nginx to serve static files from my express-deployment without ever actually hitting my express server.

In nginx this is done with the location directive where you point to files locally hosted. While I see an option for locations-snippet in the ingress-nginx configMap, I'm not entirely sure how I would have this point to files in another container.

Is this possible with ingress-nginx? If so how would I go about it? Alternatively, is this something that requires an nginx container to be hosted along side my express server? (Seems odd that I would need 2 nginx for that)

like image 596
Terence Chow Avatar asked Dec 04 '17 00:12

Terence Chow


People also ask

Is nginx Ingress a load balancer?

Coming to your query Ingress-nginx is not a load balancer but on a broader lever can help you with load balancing. 1) ingress controller - which is a traffic management solution I would say. Yes it manages the traffic using path based or host based routing.

How do I assign a static IP to ingress?

To acquire a static IP for the ingress-nginx-controller, simply put it behind a Service of Type=LoadBalancer . Then, update the ingress controller so it adopts the static IP of the Service by passing the --publish-service flag (the example yaml used in the next step already has it set to "ingress-nginx-lb").


1 Answers

In theory, you could have a PV in in RWX mode mounted to both express and ingress and provide custom config to the nginx-ingress pods, but that should be avoided. Ingress Controller has one responsibility - implement Ingress rules defined in your cluster. To serve static content you should have a pod that does that, which indeed means ie. running second nginx in your stack. The thing is, that you should treat your ingress controller as part of the infrastructure providing generic cluster functionality, and serving static files from some place (or container if they are versioned/built as docker images) is de facto part of your application.

like image 189
Radek 'Goblin' Pieczonka Avatar answered Sep 18 '22 14:09

Radek 'Goblin' Pieczonka