Creating a Custom Error Page
Custom Ambassador or Emissary Error Pages Resource
Marketplace solutions now have custom error page capability for the included Ambassador or Emissary ingress controller, using a new custom resource called ErrorPage. These pages can be global, applying to all pages in your solution, or they can be configured to apply to individual pages. You'll first add this new ErrorPage to your solution. To create a an ErrorPage inline, run a command following the steps below:
cat << EOF | kubectl apply -f -
apiVersion: "hclMarketplace.com/v1beta1"
kind: ErrorPage
metadata:
name: "myerrorpage"
namespace: "mynamespace"
spec:
service:
name: foo3-snoop
bypass: true
EOF
You can also create the same resource running the following commands:
- kubectl apply -f myerrorpage.yaml if myerrorpage.yaml is the below:
apiVersion: "hclMarketplace.com/v1beta1"
kind: ErrorPage
metadata:
name: "myerrorpage"
namespace: "mynamespace"
spec:
service:
name: foo3-snoop
bypass: true
- To create a new ErrorPage after you've installed your solution, run the following command:
apiVersion: "hclMarketplace.com/v1beta1"
kind: ErrorPage
metadata:
name: "myerrorpage"
namespace: "mynamespace"
spec:
statusCode: 404
html: <html><head><title>my custom 404</title></head><body><h1>Oops!</h1></body></html>
-
This will create a new global ErrorPage that will be shown for all 404 status codes that happen for that specific solution.
-
If you only wish to apply specific ErrorPages to a particular service mapping, follow the steps below:
apiVersion: "hclMarketplace.com/v1beta1"
kind: ErrorPage
metadata:
name: "myerrorpage-foo"
namespace: "mynamespace"
labels:
test: errorpages
spec:
statusCode: 405
html: <html><head><title>my custom 405 for foo</title></head><body><h1>Foo Oops!</h1></body></html>
service:
name: release-foo
-
It's important to understand that a service mapping with a set ErrorPage will ignore all global ErrorPages. In the example directly above, requests mapped to
release-foo
will only have a custom ErrorPage for status code405
and not404
or any other error page status codes set globally. -
If you want a particular service to ignore any global ErrorPages, you can create a null
ErrorPage
resource (with no html specified) as follows:
apiVersion: "hclMarketplace.com/v1beta1"
kind: ErrorPage
metadata:
name: "myerrorpage-foo"
namespace: "mynamespace"
labels:
test: errorpages
spec:
service:
name: release-foo
bypass: true
-
To create the custom resource, the following are required:
statusCode and html
orservice
(wherename
is required). Note: You must have either a statusCode and html together or a service that also define the name - the following combinations are accepted:- An ErrorPage that defines statusCode and html, without a service.
- An ErrorPage that does not define statusCode and html, but does define a service (with the name) and bypass property
- An ErrorPage that defines a statusCode, with html and defines a service (with name)
-
The following would be example of an invalid ErrorPage:
- An ErrorPage that defines a statusCode alone, an html alone