API gateways on Kubernetes overview
This topic provides overview information about API gateways for Consul on Kubernetes.
Introduction
API gateways enable external network clients to access applications and services running in a Consul datacenter. API gateways can also forward requests from clients to specific destinations based on path or request protocol. Systems that access services in the mesh may be internal or external to your organizational network. North-south traffic is a common term to describe this type of network traffic.
API gateway implements the Kubernetes Gateway API specification. For more information, refer to the official Kubernetes documentation
There are two API gateway controllers:
- Standard API gateway, API group
gateway.networking.k8s.io - Consul API gateway, API group
consul.hashicorp.com
Standard API gateway
The Standard API gateway is the default implementation. Developed under the gateway.networking.k8s.io is already used in previous Consul releases, tested, and accepted by the Kubernetes community.
We recommend the Standard API gateway for every new installation except when your Kubernetes platform manages the Gateway CRDs, supports only stable API versions (v1), and your applications use TCPRoute.
In this case, use the Consul API Gateway instead, as the Standard API Gateway does not support TCPRoute under these constraints.
Consul API gateway
Consul API Gateway is a Consul-specific API gateway developed under the consul.hashicorp.com API group. Use the Consul API gateway for platforms where gateway CRDs are managed externally and supporting only the stable v1 API version.
Use the Consul API gateway when your application requires TCPRoute, and either of the following conditions applies:
- The platform manages the gateway CRDs, and the CRDs support only the stable
v1API version for gateways, gateway classes, and HTTP routes, and thev1beta1API version for reference grants. - An external application or user installed the gateway CRDs, and the CRDs support only the stable
v1API version for gateways, gateway classes, and HTTP routes, and thev1beta1API version for reference grants.
Example manifests
This is an example manifest of Standard API gateway.
gateway.yaml
apiVersion: v1
items:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
labels:
component: api-gateway
name: api-gateway
namespace: consul
spec:
gatewayClassName: consul
listeners:
- allowedRoutes:
namespaces:
from: All
name: http
port: 80
protocol: HTTP
- allowedRoutes:
namespaces:
from: All
name: tcp-8090
port: 8090
protocol: TCP
Workflow
To use an API gateway on Consul:
- Verify technical specifications for your cluster. OpenShift users in particular must verify specific parameters in the Helm chart.
- Configure the API gateway to enable it.
- Configure gateway scaling if you want to manage static replicas or controller-managed HPA behavior for individual gateways.
- Deploy listeners. Configure one or more listeners to serve as ingress points for requests to services in Consul's service mesh.
- Define a route so that the listener can forward the request to the service in the mesh. Routes can be tuned to define complex traffic shaping. For example, you can Reroute HTTP requests to define URL rewrite rules for the services in your Kubernetes cluster.
Consul API gateway reference objects
Refer to the following table for the Consul API gateway resource details:
| Resources | Shortname | API Version | Namespaced | Kind |
|---|---|---|---|---|
| cgateways | cgtw | consul.hashicorp.com/v1beta1 | true | Gateway |
| cgrpcroutes | cgrpcroutes | consul.hashicorp.com/v1alpha2 | true | GRPCRoute |
| chttproutes | chttproutes | consul.hashicorp.com/v1beta1 | true | HTTPRoute |
| creferencegrants | crefgrant | consul.hashicorp.com/v1beta1 | true | ReferenceGrant |
| ctcproutes | ctcproutes | consul.hashicorp.com/v1alpha2 | true | TCPRoute |
| ctlsroutes | ctlsroutes | consul.hashicorp.com/v1alpha2 | true | TLSRoute |
| cudproutes | cudproutes | consul.hashicorp.com/v1alpha2 | true | UDPRoute |
| customgatewayclasses | cgc | consul.hashicorp.com/v1beta1 | false | CustomGatewayClass |
| customgatewaypolicies | cgp | consul.hashicorp.com/v1alpha1 | true | CustomGatewayPolicy |
Guidance
The following resources are available to help you use Consul API gateways on Kubernetes.
Tutorials
- Enable external traffic ingress into Consul service mesh
- Control access into the service mesh with Consul API gateway
Usage documentation
- Scale API gateways on Kubernetes
- Deploy API gateway listeners to Kubernetes
- Deploy API gateway routes to Kubernetes
- Reroute HTTP requests in Kubernetes
- Route traffic to peered services in Kubernetes
- Use JWTs to verify requests to API gateways on Kubernetes
Reference documentation
To use Consul API gateway on Kubernetes, you must configure the following custom resource definitions (CRDs).
| Configuration | Description |
|---|---|
Gateway | Defines the main infrastructure resource for declaring an API gateway and listeners on the gateway. It also specifies the name of the GatewayClass. |
GatewayClass | Defines a class of gateway resources used as a template for creating gateways. The default gateway class is consul and is suitable for most API gateway implementations. |
GatewayClassConfig | Describes additional gateway-related configuration parameters for the GatewayClass resource. |
Routes | Specifies paths from the gateway listener to backend services. |
MeshServices | Enables routes to reference services in Consul. |
ServiceIntentions | Specifies traffic communication rules between services in the mesh. Intentions also enforce rules for service-to-service traffic routed through a Consul API gateway. |
Troubleshooting
API gateway on Kubernetes error messages can help you troubleshoot the most common API gateway errors on Kubernetes.