This topic gives you reference information about the HTTPRoute
resource for Tanzu Platform, which routes HTTP or HTTPS traffic to a deployed Kubernetes application.
Tanzu Platform automatically creates the HTTPRoute resource when you initialize a ContainerApp
for your application using the tanzu app init
command. However, you can also create this resource manually.
HTTPRoute resource
If want to create an HTTPRoute
resource manually, create a YAML file for the resource in the .tanzu/config
directory of your repository. Define the resource as follows:
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
apps.tanzu.vmware.com/promotable: ""
apps.tanzu.vmware.com/promote-group: ContainerApp/APP-NAME
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 configuration to create the DNS record. Must be prefixed with http or https . For example, if http-APP-HOSTNAME is http-helloworld and the domain 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 | / |
Example HTTPRoute manifests
This section provides examples to help you to configure the HTTPRoute
resource.
Spring Music sample
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"
apps.tanzu.vmware.com/promotable: ""
apps.tanzu.vmware.com/promote-group: ContainerApp/spring-music
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 sample
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"
apps.tanzu.vmware.com/promotable: ""
apps.tanzu.vmware.com/promote-group: ContainerApp/spring-cloud-gateway
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: /
Content feedback and comments