This topic describes how to configure a deployment so that HTTP/HTTPS traffic can be routed to a deployed application.
Many applications, such as web applications, serve traffic via HTTP and HTTPS. In order 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 work in conjunction with the multicloud-ingress.tanzu.vmware.com defined as part of a custom networking profile. When a Space is created from these profiles, these capabilities leverages 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 have:
httproute
resources for two sample applications for different scenarios.This how-to will provide steps to create an httproute
resources for two sample applications:
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.
In order to 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:
tanzu app init
cd .tanzu/config
k8sGatewayRoutes.yaml
using the following templateapiVersion: 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 will use in combination with the domain from the multicloud-ingress 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 trait is tanzu.com , the resulting DNS record will be 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: /