Add HTTP Routing to an Application

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 you begin

Before defining a httproute resource, you 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 capability (from custom networking profile). An example Space is provided in the Getting Started guide
  • An application that you have or will deploy to the space that is expecting HTTP traffic to be routed to it. As guide, we will provide samples httproute resources for two sample applications for different scenarios.
  • Initialized the ContainerApp from the source code for the application

Overview

This how-to will provide steps to create an httproute resources for two sample applications:

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:

  1. 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
  1. 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 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 /

Create an HTTP Route manifest

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 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"
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: /
check-circle-line exclamation-circle-line close-line
Scroll to top icon