The problem
I am part of a team that are developing some microservices with kubernetes. The problem is when a service fails and NGINX ingress controller shows that ugly page where we would like to show our ones. We have several ingress (1 per service) managing subdomains with let's encrypt certificates and when a service is not available, we don't have any way to show a custom error page because Laravel can only show error pages when available, but, what if not?
The solution:
We developed a microservice just with the mission to show personalized error pages and would like to set a default service to throw all requests that can not be proccessed by the service the user is asking for. Like a type of general config annotation or tag in configMap or something like it with the name of default service.
Hi @achetronic
I think what you are looking for are error pages (instead of the default backend). There are 2 possibilities here:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-with-annotations
annotations:
nginx.org/server-snippets: |
error_page 500 /500_error.php;
error_page 401 =301 http://example.com/forbidden.html;
spec:
rules:
- host: cafe.example.com
http:
. . . etc
With this configuration for example, if your service responds to NGINX with a 500, NGINX will redirect the request to 500_error.php. Additionally, it is possible to redirect the request to an external URL, check the example and how I've set that any 401 should return a 301 redirect to http://example.com/forbidden.html;.
As you say you have 1 ingress per service, I think this is the best approach for you.
edge version of the Ingress Controller and will be part of the next release 1.7.0 (target is April for the next release). Learn more about our release process here.Let me know if this makes sense, thanks!
PS: If this does not work, and you still want to change the default 404 for the default server, I'll discuss with the team and get back to you soon.
Before anything, I appreciate your answer and thank you for that.
In my case, I have services that manage error pages on its own but was talking about default backend for the case that Ingress Controller don't find a subdomain/path defined into an ingress resource. It would be an awesome feature to have an annotation for default-backend.
It would be useful if you manage a k8s cluster and make a mistake like kubectl delete -f . on an ingress of a whole service
In that case you could route all the traffic to a default service with an NGINX (or Laravel, or something like that) showing a message like "Service not available at this moment because we are bad wizards" or whatever.
Regards!
Hi @achetronic thanks for the clarification.
In your specific use case (someone removes the Ingress Resource from the cluster) all the methods we normally provide for error fallback won't work, because we define them at the ingress level (with annotations for instance).
I think we are not working in adding more capabilities to the Ingress Resources for now, since we are focused in NGINX Ingress Resources (VirtualServer and VirtualServerRoute).
However, there is one thing that should work for you. You can use custom templates to modify the main NGINX template. Specifically, edit this location. This is the default location for the default backend. You can specify static html files or a name of a service of your cluster.
Thanks!
Hello Ra煤l,
Is it possible to do it with your VirtualServer resources? If not, i would modify the template to redirect that 404 to an internal service as you told me, but if i can do it in your way, i will test it.
Regards :)
Not for now no, we're working on the features of VirtualServer resources, but there are a lot ofd new features we want to add so we are start with the most common use cases first.
However, I'd like to keep this Issue open, we're still discussing if we are going to offer a way to define a default service for the default backend, stay tunned!
@Rulox is it possible to customize errors coming from nginx only, like when having special characters (%) in url which nginx cannot handle properly? I posted a question on https://stackoverflow.com/questions/63290959/handle-bad-request-errors-with-nginx-ingress-controller.
@aleksvidak in your stack overflow question you're saying you are using the Community Ingress Controller (https://github.com/kubernetes/ingress-nginx)
Note how that repository is different than this one. If you are using that Ingress Controller, I suggest you open an issue there instead, as the two projects are different. If you are using this Ingress Controller, I suggest you open a new issue here so we can help you, as your problem seems to be different than the one in this thread.
Thanks
@Rulox Sorry, you are right.