Enable external traffic ingress into Consul service mesh
In this tutorial, you will enable external access into your service mesh by deploying a Consul API Gateway. Consul API Gateway provides a consistent method to handle inbound requests and route them to the appropriate service within your service mesh.
To set up ingress into your service mesh, you will:
- Enable Consul ingress features
- Deploy Consul API Gateway
- Deploy RBAC and Reference Grant resources
- View Consul services with the CLI, UI, and/or API
- Explore ingress into the HashiCups UI
Prerequisites
The tutorial assumes that you have completed the previous tutorials in this getting started collection.
For this tutorial, you will need:
Enable Consul ingress features
You will now enable additional Consul features in your Kubernetes cluster using the official Consul Helm chart or the consul-k8s
CLI.
Consul API Gateway implements and is configured through the Kubernetes Gateway API Specification. This specification defines a set of custom resource definitions (CRDs) that can create logical gateways which route traffic based on a client request's path or protocol. As of Consul 1.16, API Gateway is built into Consul which simplifies the installation and configuration process.
Review the additional configuration details.
Since these Consul resources are managed with Terraform, the respective module's Helm configuration file controls the Helm chart deployment for this environment.
Update your Consul deployment's Helm chart values.
Then, deploy the resources. Confirm the run by entering yes
.
Deploy Consul API Gateway
Review Consul API Gateway configuration
Now that you have enabled ingress features in your Consul service mesh, you can deploy the Consul API Gateway and associated HTTP Routes to your Kubernetes cluster. The Consul API Gateway uses HTTP Routes to route traffic to your applications.
Review the api-gw/consul-api-gateway.yaml
configuration file. This file contains the configuration for the API Gateway pod, the listener, and TLS attributes.
Review the api-gw/routes.yaml
configuration file. This file contains the configuration for HTTP routing including the network traffic rules and the backend service that will receive the ingress traffic.
Deploy Consul API Gateway
Next, deploy the API Gateway, wait for the API Gateway to completely deploy, deploy the routes and apply the intentions for the API Gateway.
Expected output:
Verify you have created all the pods in your consul
namespace. You should find an output similar to the following.
The diagram below shows the services running in your Kubernetes cluster. This includes Consul API Gateway, service mesh layer, and HashiCups microservice application pods.
Consul API Gateway enables ingress, load-balancing, and other advanced traffic behavior for your service mesh applications. In this tutorial, Consul API Gateway allows external traffic into the HashiCups service.
Deploy RBAC and Reference Grant resources
Now that Consul API Gateway is operational in your cluster, you will deploy role-based access control (RBAC) and Reference Grant resources. RBAC enables the Consul API gateway to interact with Consul datacenter resources and reference grants enable the Consul API Gateway to route traffic between different namespaces.
Deploy the RBAC and Reference Grant resources.
View Consul services
In this section, you will view your Consul services with the CLI, UI, and/or API to explore the details of your service mesh ingress.
In your terminal, run the CLI command consul catalog services
to return the api-gateway
service registered in Consul.
Return the list of Consul intentions. Notice that there is an intention between api-gateway
and nginx
to allow traffic between the two services.
Explore ingress into the demo application
Set your Consul API Gateway address to the CONSUL_APIGW_ADDR
environment variable.
Output the Consul API Gateway value to your terminal and paste it in your browser to access the HashiCups UI through the API Gateway.
For more information on accessing service mesh services via the Consul API Gateway, visit the Consul API Gateway documentation page.
Next steps
In this tutorial, you enabled Consul ingress features and deployed Consul API Gateway into your Kubernetes cluster. After deploying Consul API Gateway, you accessed the demo application HashiCups through the Consul API Gateway endpoint and explored how ingress into a service mesh application works.
In the next tutorial, you will deploy an observability suite to explore metrics, logs, and distributed traces within your Consul service mesh.
For more information about the topics covered in this tutorial, refer to the following resources: