This topic tells you how to configure a deployment so that you can route HTTP or HTTPS traffic to a deployed application.
Many applications, such as web applications, serve traffic using HTTP and HTTPS. To route this traffic to a deployed application, the Tanzu provided spring-dev.tanzu.vmware.com
and spring-prod.tanzu.vmware.com
Profiles include the k8sgateway.tanzu.vmware.com
Capability that works in conjunction with the multicloud-ingress.tanzu.vmware.com
Trait defined as part of a custom networking profile.
When a Space is created from these Profiles, these Capabilities use an httproute
resource to create a DNS based Global Service Load Balancer (GSLB) and route ingress traffic from the GLSB to a Kubernetes Gateway in the Space, then to the corresponding Kubernetes services that are created for the application.
This httproute
resource is manually defined in your application before deployment. This how-to will walk you through how to create this resource to route traffic to a deployed application.
Before defining a httproute
resource, you must have:
Created a Space using Profiles that require the k8sgateway.tanzu.vmware.com
Capability (from spring-dev.tanzu.vmware.com
and spring-prod.tanzu.vmware.com
Tanzu provided Profiles) and multicloud-ingress.tanzu.vmware.com
Trait (from custom networking profile).
An example Space is provided in the Getting Started guide.
An application that you want to deploy to the Space that is expecting HTTP traffic to be routed to it. As a guide, this topic provides example httproute
resources for two sample applications for different scenarios.
Initialized the ContainerApp from the source code for the application.
This how-to will provide steps to create httproute
resources for two sample applications:
A simple sample application that routes traffic directly to the Kubernetes services.
Used in the Getting Started Guide which includes the use of Spring Cloud Gateway. The httproute
routes traffic to the Spring Cloud Gateway, which then routes traffic to the correct Kubernetes service based on the route.
Before exploring httproute
for example apps, here is how to create a basic httproute
resource and explore the values.
For the traffic to be routed to your application, you need to create the manifest after the ContainerApp has been initialized so that it can be deployed with tanzu deploy
. To do this, do the following:
Navigate to the .tanzu/config
directory within the your repository that was created when you initialized an app with the tanzu app init
.
cd .tanzu/config
Create a file named k8sGatewayRoutes.yaml
using the following template
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: <APP-NAME>-route
annotations:
healthcheck.gslb.tanzu.vmware.com/service: <APP-NAME>
healthcheck.gslb.tanzu.vmware.com/path: <HEALTHCHECK-PATH>
healthcheck.gslb.tanzu.vmware.com/port: <HEALTHCHECK-PORT>
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: default-gateway
sectionName: http-<APP-HOSTNAME> #use https for TLS
rules:
- backendRefs:
- group: ""
kind: Service
name: <APP-NAME>
port: <APP-PORT>
weight: 1
matches:
- path:
type: PathPrefix
value: <APP-PATH>
Where:
Variable | Description | Example |
---|---|---|
APP-NAME |
The name of the application specified by the tanzu deploy command |
helloworld |
HEALTHCHECK-PATH |
The path that the application provides the health check service on | / |
HEALTHCHECK-PORT |
The port that the application provides the health check service on | 8080 |
APP-HOSTNAME |
The hostname that the GSLB uses in combination with the domain from the multicloud-ingress.tanzu.vmware.com Trait configuration to create the DNS record. Must be prefixed with http or https . For example, if this is http-helloworld and the multicloud-ingress.tanzu.vmware.com Trait is tanzu.com , the resulting DNS record is helloworld.tanzu.com . |
http-helloworld |
APP-PORT |
The port that the Kubernetes services is listening on for HTTP requests | 80 |
APP-PATH |
The path for the application | / |
Spring Music: is a simple application that requires traffic to be routed in to the Space from the multicloud-ingress, directly to the Kubernetes service, and then to the pods hosting the service. The httproute
resource for this sample app is as follows:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: spring-music-route
annotations:
healthcheck.gslb.tanzu.vmware.com/service: spring-music
healthcheck.gslb.tanzu.vmware.com/path: /
healthcheck.gslb.tanzu.vmware.com/port: "8080"
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: default-gateway
sectionName: http-spring-music
rules:
- backendRefs:
- group: ""
kind: Service
name: spring-music
port: 8080
weight: 1
matches:
- path:
type: PathPrefix
value: /
Where for Dinner: uses Spring Cloud Gateway. The httproute
routes traffic to the Spring Cloud Gateway, which then routes traffic to the correct Kubernetes service based on the route. The httproute
resource for this sample app is as follows:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: where-for-dinner-scg-route
annotations:
healthcheck.gslb.tanzu.vmware.com/service: spring-cloud-gateway
healthcheck.gslb.tanzu.vmware.com/path: /
healthcheck.gslb.tanzu.vmware.com/port: "80"
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: default-gateway
sectionName: http-where-for-dinner
rules:
- backendRefs:
- group: ""
kind: Service
name: spring-cloud-gateway
port: 80
weight: 1
matches:
- path:
type: PathPrefix
value: /