Redirect a client ΒΆ

The Nais platform support two ways to exposing your application, either via an Ingress resource, or through service discovery. This means that we also support two ways to redirect your application.

Ingress ΒΆ

To redirect traffic from one domain to another, you need to define an ingress from the old domain that redirects to the new domain, with .spec.redirects[].

The redirects field specifies URL redirects. It is structured as a mapping from a source URL to a target URL.

A successful redirect will return a 302 Moved Temporarily HTTP status code with location header set to the target URL.

  • The status code can not be overridden.
  • The from and to URLs must be valid URLs.
  • The to URL must be a valid URL that is exposed by the application.

Explicit redirect permission

If the redirection is between two teams/namespaces, the following annotation needs to be set on the old Nais application

yaml

Structure ΒΆ

.nais/app.yaml

Parameters ΒΆ

  • from: (string) The source URL for the redirection. This is the URL that will be redirected.
  • to: (string) The target URL for the redirection. This is the URL that the client will be redirected to.

Usage Example ΒΆ

.nais/app.yaml

In this example:

  • Requests to http://example-old.nais.io are redirected to http://example-new.nais.io.

Service discovery ΒΆ

To redirect traffic coming through service discovery you need to create a service in the old namespace pointing to the new app/service in the new namespace. This is not a part of the Nais application specification, so you need to create and deploy a separate file for this.

Access policy

Remember that access policy is traffic between pods, so if you redirect the traffic to a different namespace, the client needs to update their access policy to use the new namespace.

Structure ΒΆ

.nais/service.yaml

Deploy either through Github Actions, or using kubectl apply -f .nais/service.yaml.