Skip to content

wftech/nginx-ingress-error-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Error backend for nginx ingress

Warning: This repository is Proof Of Concept.

This is default backend for Nginx ingress Controller. It is based on the example error backend with predefined error pages and Go templating. We have fixed some errors and added few new ones.

We used haproxy error pages from Jonathan Rosewood as a base for the error messages. Thank you.

How to build and test

# build static image
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o custom-error-pages

# run 
DEBUG=1 ERROR_FILES_PATH=./rootfs/www ./custom-error-pages

# run with custom error pages
DEBUG=1 ERROR_FILES_PATH=./rootfs/www CUSTOM_ERROR_FILES_PATH=./rootfs/www.override ./custom-error-pages

# test in other terminal
curl localhost:8080 -H 'X-Code: 502' -I
curl localhost:8081/metrics

There is default HTTP backend on port 8080. You should use this as your ingress default backend. There is secondary port 8081, which can be used for health checking (on /healthz URI) and monitoring (/metrics)

How to build Docker image

# build static Docker image
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o custom-error-pages
docker build -t localhost/custom-error -f Dockerfile.devel .

# run and test the image
docker run --rm -it -e DEBUG=1 -p 8080:8080 -p 8081:8081 localhost/custom-error:latest

How to deploy

  1. deploy the image to Deployment

  2. deply Service named default-backend to some namespace ( we use ingress-nginx )

  3. according to the ingress parameters, update command line arguments to set default backend. --default-backend-service=ingress-nginx/default-backend

  4. Add custom-http-errors: 503,502,403 to ingress config map.

  5. Watch metrics default_http_backend_http_error_count_total > 0.

Example manifests are available at GitHub repository. You still have to modify ingress config.

License

Apache 2 (same as from original example)

About

Nginx ingress error backend used as error backend

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages