Route one port of a destination
Use sectionName to route a single named port of a MeshService, leaving its other ports alone.
Configuration
apiVersion: kuma.io/v1alpha1
kind: MeshTCPRoute
metadata:
name: frontend-to-backend-db
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
sectionName: postgres
rules:
- default:
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: backend-replica
port: 5432Copied!
type: MeshTCPRoute
name: frontend-to-backend-db
mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: frontend
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
sectionName: postgres
rules:
- default:
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: backend-replica
port: 5432Copied!
Adjust konnect_mesh_control_plane.my_meshcontrolplane.id and konnect_mesh.my_mesh.name according to your current configuration.
resource "konnect_mesh_tcp_route" "frontend_to_backend_db" {
provider = konnect-beta
type = "MeshTCPRoute"
name = "frontend-to-backend-db"
spec = {
target_ref = {
kind = "Dataplane"
labels = {
app = "frontend"
}
}
to = [
{
target_ref = {
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
section_name = "postgres"
}
rules = [
{
default = {
backend_refs = [
{
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend-replica"
}
port = 5432
}
]
}
}
]
}
]
}
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!