내장 라우트 구성
내장 라우트 구성 (MeshHTTPRoute 및 MeshTCPRoute)
게이트웨이 리스너에서 메시 서비스로 트래픽이 어떻게 전달될지 설정하려면 MeshHTTPRoute와 MeshTCPRoute 정책을 사용해요. 이 문서에서는 Kubernetes, Universal, Terraform 환경별로 라우트 리소스를 작성하는 예제를 소개해요. 게이트웨이와 함께 이 라우트 리소스를 사용할 때는 spec.targetRef로 게이트웨이 데이터 플레인 프록시를 대상으로 지정해야 해요. 또한 내장 게이트웨이에서는 spec.to[].targetRef가 kind: Mesh로 제한된다는 점도 기억해요
출처: 문서
본문
게이트웨이와 함께 이러한 라우트 리소스를 사용할 때는 spec.targetRef를 사용해 게이트웨이 데이터 플레인 프록시를 대상으로 지정해야 해요.
빌트인 게이트웨이와 함께
MeshHTTPRoute와MeshTCPRoute를 사용할 때는spec.to[].targetRef가kind: Mesh로 제한돼요.
MeshHTTPRoute
MeshHTTPRoute 리소스의 예시예요:
Kubernetes
kuma.io/service 태그 기반 네이밍을 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: edge-gateway-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
port: http-8080
to:
- targetRef:
kind: Mesh
hostnames:
- example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: demo-app_kuma-demo_svc_5000
MeshService Kubernetes 리소스를 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: edge-gateway-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
port: http-8080
to:
- targetRef:
kind: Mesh
hostnames:
- example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: demo-app
namespace: kuma-demo
port: 5000
Universal
kuma.io/service 태그 기반 네이밍을 사용하는 경우:
type: MeshHTTPRoute
name: edge-gateway-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
port: http-8080
to:
- targetRef:
kind: Mesh
hostnames:
- example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: demo-app
MeshService Kubernetes 리소스를 사용하는 경우:
type: MeshHTTPRoute
name: edge-gateway-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
port: http-8080
to:
- targetRef:
kind: Mesh
hostnames:
- example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: demo-app
port: 5000
Terraform
현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}
resource "konnect_mesh_http_route" "edge_gateway_route" {
provider = konnect-beta
type = "MeshHTTPRoute"
name = "edge-gateway-route"
spec = {
target_ref = {
kind = "MeshGateway"
name = "edge-gateway"
tags = {
port = "http-8080"
}
}
to = [
{
target_ref = {
kind = "Mesh"
}
hostnames = [
= "example.com"
]
rules = [
{
matches = [
{
path = {
type = "PathPrefix"
value = "/"
}
}
]
default = {
backend_refs = [
{
kind = "MeshService"
name = "demo-app"
port = "5000"
}
]
}
}
]
}
]
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
리스너 호스트네임
MeshGateway 리스너에는 프로토콜에 따라 리스너가 받아들이는 트래픽을 제한하는 선택적인 hostname 필드가 있어요:
- HTTP: Host 헤더가 일치해야 해요
- TLS: SNI가 일치해야 해요
- HTTPS: SNI와 host가 모두 일치해야 해요
라우트를 특정 리스너에 연결하면 라우트들이 서로 격리돼요. 다음과 같은 리스너가 있다고 가정해 볼게요:
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
hostname: foo
- port: 8080
protocol: HTTP
hostname: *.example.com
tags:
hostname: wild
여기에 다음 MeshHTTPRoute 규칙이 있다고 해 볼게요:
Kubernetes
kuma.io/service 태그 기반 네이밍을 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: http-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
hostname: wild
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example_app_svc_8080
MeshService Kubernetes 리소스를 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: http-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
hostname: wild
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example
namespace: app
port: 8080
Universal
kuma.io/service 태그 기반 네이밍을 사용하는 경우:
type: MeshHTTPRoute
name: http-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
hostname: wild
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example
MeshService Kubernetes 리소스를 사용하는 경우:
type: MeshHTTPRoute
name: http-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
tags:
hostname: wild
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example
port: 8080
Terraform
현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}
resource "konnect_mesh_http_route" "http_route" {
provider = konnect-beta
type = "MeshHTTPRoute"
name = "http-route"
spec = {
target_ref = {
kind = "MeshGateway"
name = "edge-gateway"
tags = {
hostname = "wild"
}
}
to = [
{
target_ref = {
kind = "Mesh"
}
rules = [
{
matches = [
{
path = {
type = "PathPrefix"
value = "/"
}
}
]
default = {
backend_refs = [
{
kind = "MeshService"
name = "example"
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
}
이 라우트는 hostname: *.example.com을 가진 두 번째 리스너에 명시적으로 연결돼요.
즉, 더 구체적이기 때문에 첫 번째 리스너와 매칭되는 foo.example.com으로의 요청은 해당 리스너에 연결된 라우트가 없기 때문에 404를 반환하게 돼요.
라우트 호스트네임
MeshHTTPRoute 규칙은 해당 규칙이 처리하는 트래픽을 더 한정하기 위해 호스트네임 목록을 추가로 지정할 수 있어요. 예를 들어:
Kubernetes
kuma.io/service 태그 기반 네이밍을 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: http-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v1_app_svc_8080
- targetRef:
kind: Mesh
hostnames:
- dev.example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v2_app_svc_8080
MeshService Kubernetes 리소스를 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: http-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v1
namespace: app
port: 8080
- targetRef:
kind: Mesh
hostnames:
- dev.example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v2
namespace: app
port: 8080
Universal
kuma.io/service 태그 기반 네이밍을 사용하는 경우:
type: MeshHTTPRoute
name: http-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v1
- targetRef:
kind: Mesh
hostnames:
- dev.example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v2
MeshService Kubernetes 리소스를 사용하는 경우:
type: MeshHTTPRoute
name: http-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v1
port: 8080
- targetRef:
kind: Mesh
hostnames:
- dev.example.com
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: example-v2
port: 8080
Terraform
현재 설정에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}
resource "konnect_mesh_http_route" "http_route" {
provider = konnect-beta
type = "MeshHTTPRoute"
name = "http-route"
spec = {
target_ref = {
kind = "MeshGateway"
name = "edge-gateway"
}
to = [
{
target_ref = {
kind = "Mesh"
}
rules = [
{
matches = [
{
path = {
type = "PathPrefix"
value = "/"
}
}
]
default = {
backend_refs = [
{
kind = "MeshService"
name = "example-v1"
port = "8080"
}
]
}
}
]
},
{
target_ref = {
kind = "Mesh"
}
hostnames = [
= "dev.example.com"
]
rules = [
{
matches = [
{
path = {
type = "PathPrefix"
value = "/"
}
}
]
default = {
backend_refs = [
{
kind = "MeshService"
name = "example-v2"
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
}
이 라우트는 dev.example.com으로 가는 모든 트래픽을 v2 백엔드로 보내고, 다른 트래픽은 v1으로 보내요.
MeshTCPRoute
트래픽이 HTTP가 아니라면 MeshTCPRoute를 사용해 서비스 간 트래픽을 분산할 수 있어요:
Kubernetes
kuma.io/service 태그 기반 이름을 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshTCPRoute
metadata:
name: tcp-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- default:
backendRefs:
- kind: MeshService
name: example-v1_app_svc_8080
weight: 90
- kind: MeshService
name: example-v2_app_svc_8080
weight: 10
MeshService Kubernetes 리소스를 사용하는 경우:
apiVersion: kuma.io/v1alpha1
kind: MeshTCPRoute
metadata:
name: tcp-route
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- default:
backendRefs:
- kind: MeshService
name: example-v1
namespace: app
port: 8080
weight: 90
- kind: MeshService
name: example-v2
namespace: app
port: 8080
weight: 10
Universal
kuma.io/service 태그 기반 이름을 사용하는 경우:
type: MeshTCPRoute
name: tcp-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- default:
backendRefs:
- kind: MeshService
name: example-v1
weight: 90
- kind: MeshService
name: example-v2
weight: 10
MeshService Kubernetes 리소스를 사용하는 경우:
type: MeshTCPRoute
name: tcp-route
mesh: default
spec:
targetRef:
kind: MeshGateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
rules:
- default:
backendRefs:
- kind: MeshService
name: example-v1
port: 8080
weight: 90
- kind: MeshService
name: example-v2
port: 8080
weight: 10
Terraform
현재 구성에 맞게 konnect_mesh_control_plane.my_meshcontrolplane.id와 konnect_mesh.my_mesh.name을 조정하세요. {: .text-sm}
resource "konnect_mesh_tcp_route" "tcp_route" {
provider = konnect-beta
type = "MeshTCPRoute"
name = "tcp-route"
spec = {
target_ref = {
kind = "MeshGateway"
name = "edge-gateway"
}
to = [
{
target_ref = {
kind = "Mesh"
}
rules = [
{
default = {
backend_refs = [
{
kind = "MeshService"
name = "example-v1"
port = "8080"
weight = "90"
},
{
kind = "MeshService"
name = "example-v2"
port = "8080"
weight = "10"
}
]
}
}
]
}
]
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
관련 리소스
더 알아보기 (Learn more)
- 리스너에서 메시 서비스로 HTTP 트래픽을 전달하는 라우트 정책의 자세한 내용이에요 —
MeshHTTPRoute - TCP 트래픽 라우팅에 사용하는 정책의 자세한 내용이에요 —
MeshTCPRoute - 정책이 어떤 프록시에 적용될지 지정하는 targetRef 개념을 설명해요 —
spec.targetRef - 내장 게이트웨이의 개념과 동작 방식을 먼저 이해하면 좋아요 — Built-in gateways
- 내장 게이트웨이를 처음부터 설정하는 실습 가이드예요 — Set up a built-in gateway
- 리스너 호스트네임 구성 방법을 다루는 관련 문서예요 — Configuring built-in listeners