Introduction
This guide shows you how to route traffic to a Kubernetes Service through Tyk Gateway, using the Kubernetes Gateway API. You will:- Install the Kubernetes Gateway API resource definitions.
- Enable Kubernetes Gateway API support in Tyk Operator.
- Configure your Tyk Gateways to serve the APIs for a
Gateway. - Connect a
GatewayClassand aGatewayto your Tyk deployment. - Create an
HTTPRoute, and check that it works.
Prerequisites
You need:- Tyk Operator 1.6.0 or later, installed and connected to Tyk Dashboard
- Tyk Gateways that run in the cluster, with a Kubernetes Service in front of them
- a Kubernetes Service to route traffic to, such as
httpbinon port80in thedefaultnamespace, which this guide uses kubectlandhelm, with access to the cluster
WATCH_NAMESPACE, include the namespaces of your OperatorContexts, Gateway and HTTPRoute resources. In this guide, those are tyk-operator-system, tyk and default.
Install the Kubernetes Gateway API Resource Definitions
Install the Kubernetes Gateway API custom resource definitions (CRDs) from the experimental channel:--server-side, because the experimental CRDs are too large for a client-side apply.
Enable Kubernetes Gateway API Support in Tyk Operator
Tyk Operator doesn’t watch Kubernetes Gateway API resources by default. To enable it, setenableGatewayAPI to true in the Tyk Operator Helm chart:
Configure Your Tyk Gateways
EachGateway represents a group of Tyk Gateways that serve its APIs. Tyk Operator tags every API that it creates for a Gateway with the API sharding tags of that group. Configure the Tyk Gateways in the group to load only the APIs with those tags.
Set these options on each Tyk Gateway in the group:
Connect Kubernetes to Your Tyk Deployment
You link the Kubernetes Gateway API resources to Tyk with two OperatorContext resources.Create the Tyk Dashboard Context
TheGatewayClass uses this OperatorContext to connect to Tyk Dashboard. It can refer to the same Secret that you created when you installed Tyk Operator, which holds TYK_URL, TYK_AUTH, TYK_ORG and TYK_MODE: pro:
Create the Data Plane Context
TheGateway uses this OperatorContext to identify its Tyk Gateways. Create it in the namespace of the Kubernetes Service in front of those Tyk Gateways:
Create the GatewayClass
Create aGatewayClass that Tyk Operator manages, and refer it to the Tyk Dashboard context:
GatewayClass resources whose controllerName is tyk.io/gateway-controller. The parametersRef must include the namespace of the OperatorContext.
Create the Gateway
Create aGateway in the same namespace as the data plane context, and refer it to that context in spec.infrastructure:
HTTP or HTTPS protocol, and a port that the Kubernetes Service of the data plane exposes.
Always set
infrastructure.parametersRef. Without it, any Tyk Gateway that isn’t segmented loads the APIs of the Gateway. See Gateways Without a Data Plane Context.Create an HTTPRoute
Create anHTTPRoute that sends requests for /orders on api.example.com to the httpbin Service. The URLRewrite filter removes /orders from the path before the request reaches the Service:
/orders/get.
Check the Result
Check that Tyk Operator has accepted each resource:- The
GatewayClasshas the conditionAcceptedset toTrue. - The
Gatewayhas the conditionProgrammedset toTrue, and an address instatus.addresses. - The
HTTPRoutehas the conditionsAcceptedandResolvedRefsset toTrue, for theedgeparent.
False, its reason and message explain the problem. See Status and Troubleshooting.
Then send a request through Tyk Gateway, using the address of the Gateway:
ClusterIP or NodePort Service, you might not be able to reach its address from your machine. Forward a local port to the Service instead:
localhost:
httpbin Service receives the request for /get.
This API has no authentication. Any client that can reach the Tyk Gateway can call it. To add authentication, see Secure and Extend Routes.