Route paths to different destinations
Send /orders to the orders service and everything else to backend, using a catch-all rule so unmatched paths are not answered with a 404.
Configuration
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: frontend-to-backend
namespace: kong-mesh-demo
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: frontend
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
rules:
- matches:
- path:
type: PathPrefix
value: "/orders"
default:
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: orders
port: 8080
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: backend
port: 8080Copied!
type: MeshHTTPRoute
name: frontend-to-backend
mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: frontend
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
rules:
- matches:
- path:
type: PathPrefix
value: "/orders"
default:
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: orders
port: 8080
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: backend
port: 8080Copied!
Adjust konnect_mesh_control_plane.my_meshcontrolplane.id and konnect_mesh.my_mesh.name according to your current configuration.
resource "konnect_mesh_http_route" "frontend_to_backend" {
provider = konnect-beta
type = "MeshHTTPRoute"
name = "frontend-to-backend"
spec = {
target_ref = {
kind = "Dataplane"
labels = {
app = "frontend"
}
}
to = [
{
target_ref = {
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
}
rules = [
{
matches = [
{
path = {
type = "PathPrefix"
value = "/orders"
}
}
]
default = {
backend_refs = [
{
kind = "MeshService"
labels = {
"kuma.io/display-name" = "orders"
}
port = 8080
}
]
}
},
{
matches = [
{
path = {
type = "PathPrefix"
value = "/"
}
}
]
default = {
backend_refs = [
{
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
port = 8080
}
]
}
}
]
}
]
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
Copied!