このページは、まだ日本語ではご利用いただけません。翻訳中です。
旧バージョンのドキュメントを参照しています。 最新のドキュメントはこちらをご参照ください。
Routing by Header
In addition to URL components, Kong Gateway can route HTTP requests using request header values. This guide will walk through creating routes that use the same URL, but send traffic to different upstream services based on the requests’ headers.
Installation
Follow the deployment documentation to install the Kong Ingress Controller on your Kubernetes cluster.
Test connectivity to Kong Gateway
This guide assumes that the PROXY_IP
environment variable is
set to contain the IP address or URL pointing to Kong Gateway.
Follow one of the
deployment guides to configure this environment variable.
If everything is setup correctly, making a request to Kong Gateway should return
a HTTP 404
status code.
This is expected because Kong Gateway does not yet know how to proxy the request.
Install an example service
We will start by installing the echo service and increasing its replica count:
Setup Ingress
Let’s expose the echo service outside the Kubernetes cluster by defining an Ingress:
Test the echo service:
Adding header rules to the Ingress
The konghq.com/headers.*
annotation controls the headers
field on Kong Gateway
routes generated from Ingress resources. When set, these headers must be
present with a specific value for a request to match a route.
The header name is configured by replacing the *
in the example above with a
header name. The konghq.com/headers.x-split
and konghq.com/headers.x-legacy
annotations indicate allowed values for the x-split
and x-legacy
headers,
respectively. To start, add one of these to the demo-a
Ingress:
Requests will no longer match the route:
Add another Ingress
To demonstrate header routing, add another Ingress with a rule for the same
path as demo-a
:
This Ingress will accept a different set of values for x-split
and
will require an x-legacy
header:
Send requests with headers
Add headers to your requests to make your requests match routes again. You’ll be able to access both routes depending on which header you use:
Note that demo-b
requires both headers, but matches any of the
individual values configured for a given header.