A new platform for documentation and tutorials is launching soon.
We are migrating Consul documentation into HashiCorp Developer, our new developer experience.
This topic describes how to use Consul API Gateway.
Complete the following steps to use Consul API Gateway in your network.
Verify that the requirements have been met.
Verify that the Consul API Gateway CRDs and controller have been installed and applied (see Installation).
apiGateway: enabled: true managedGatewayClass:
kubectl applycommand to implement the configurations, e.g.:
$ kubectl apply -f gateway.yaml routes.yaml
»Reroute HTTP requests
Configure the following fields in your
Route configuration to use this feature. Refer to the Route configuration reference for details about the parameters.
rules.filters.type: Set this parameter to
URLRewriteto instruct Consul API Gateway to rewrite the URL when specific conditions are met.
rules.filters.urlRewrite: Specify the
rules.filters.urlRewrite.path: Contains the paths that incoming requests should be rewritten to based on the match conditions.
Note that if the route is configured to accept paths with and without a trailing slash, you must make two separate routes to handle each case.
In the following example, requests to
/incoming-request-prefix/ are forwarded to the
/prefix-backend-receives/. A request to
/incoming-request-prefix/request-path, for instance, is received by the
apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute metadata: name: example-route ##... spec: parentRefs: - group: gateway.networking.k8s.io kind: Gateway name: api-gateway rules: - backendRefs: . . . filters: - type: URLRewrite urlRewrite: path: replacePrefixMatch: /prefix-backend-receives/ type: ReplacePrefixMatch matches: - path: type: PathPrefix value: /incoming–request-prefix/
This topic provides information about potential error messages associated with Consul API Gateway. If you receive an error message that does not appear in this section, refer to the following resources:
»Helm installation failed: "no matches for kind"
Error: INSTALLATION FAILED: unable to build kubernetes objects from release manifest: [unable to recognize "": no matches for kind "GatewayClass" in version "gateway.networking.k8s.io/v1alpha2", unable to recognize "": no matches for kind "GatewayClassConfig" in version "api-gateway.consul.hashicorp.com/v1alpha1"]
Conditions: Consul API Gateway generates this error when the required CRD files have not been installed in Kubernetes prior to installing Consul API Gateway.
Impact: The installation process typically fails after this error message is generated.
Recommended Action: Install the required CRDs by using the command in Step 1 of the Consul API Gateway installation instructions and then retry installing Consul API Gateway.