MeshGateway로 내장 리스너 구성하기
MeshGateway로 내장 리스너 구성하기 (Configuring built-in listeners with MeshGateway)
내장 게이트웨이의 리스너를 구성하려면 MeshGateway 리소스를 사용해요. 이 리소스는 게이트웨이가 어떤 네트워크 포트에서 트래픽을 받아들이고 어떻게 처리할지 결정해줘요. 리스너에 포트와 프로토콜, 호스트명을 지정하는 방법부터 TLS 종료와 멀티존 구성까지 차근차근 살펴봐요
출처: 문서
본문
MeshGateway 리소스는 게이트웨이가 어떤 네트워크 포트에서 리스닝해야 하는지, 그리고 네트워크 트래픽을 어떻게 수락해야 하는지 지정해요.
내장 게이트웨이 데이터 플레인에는 정확히 하나의 MeshGateway 리소스만 바인딩될 수 있어요.
이 바인딩은 표준적인 태그 기반 Kong Mesh 매칭 시맨틱스를 사용해요:
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: edge-gateway
spec:
selectors:
- match:
kuma.io/service: edge-gateway_default_svc
Universal
type: MeshGateway
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
MeshGateway는 원하는 만큼 많은 리스너를 가질 수 있고, 각 리스너는 네트워크 트래픽을 수락할 수 있는 엔드포인트를 나타내요.
MeshGateway는 어떤 IP 주소를 리스닝하는지 지정하지 않아요. 그걸 지정하는 건 Dataplane 리소스예요.
리스너를 구성하려면 최소한 포트 번호와 네트워크 프로토콜을 지정해야 해요. 각 리스너는 자체적인 Kong Mesh 태그 집합을 가질 수도 있어서, Kong Mesh 정책 구성이 특정 리스너를 대상으로 삼을 수 있어요.
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: edge-gateway
spec:
selectors:
- match:
kuma.io/service: edge-gateway_default_svc
conf:
listeners:
- port: 8080
protocol: HTTP
tags:
port: http-8080
Universal
type: MeshGateway
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
conf:
listeners:
- port: 8080
protocol: HTTP
tags:
port: http-8080
호스트네임
HTTP 또는 HTTPS 리스너는 hostname도 지정할 수 있어요.
리스너는 port와 protocol을 공유하면서 hostname만 서로 다르게 가질 수 있다는 점에 유의하세요.
이렇게 하면 특정 호스트네임으로 오는 요청에 라우트를 연결하면서도, 다른 호스트네임에 연결된 다른 라우트들과 포트/프로토콜을 공유할 수 있어요.
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: edge-gateway
spec:
selectors:
- match:
kuma.io/service: edge-gateway_default_svc
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
port: http-8080
Universal
type: MeshGateway
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
port: http-8080
위 예제에서 게이트웨이 프록시는 TCP 포트 8080에서 HTTP 프로토콜 연결을 리스닝하지만, Host 헤더는 foo.example.com으로 제한해요.
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: edge-gateway
spec:
selectors:
- match:
kuma.io/service: edge-gateway_default_svc
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
vhost: foo.example.com
- port: 8080
protocol: HTTP
hostname: bar.example.com
tags:
vhost: bar.example.com
Universal
type: MeshGateway
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
vhost: foo.example.com
- port: 8080
protocol: HTTP
hostname: bar.example.com
tags:
vhost: bar.example.com
위 예제는 같은 포트에 두 개의 HTTP 리스너를 둔 MeshGateway 리소스를 보여줘요.
이 경우 게이트웨이 프록시는 포트 8080에서 리스닝하도록 구성되고, 두 호스트네임 모두에 대한 HTTP 요청을 수락해요.
각 리스너 항목이 자체적인 Kong Mesh 태그를 갖고 있기 때문에, 정책은 여전히 특정 리스너를 대상으로 삼을 수 있어요.
Kong Mesh는 리스너, MeshGateway, Dataplane의 태그를 결합해서 각 리스너별 태그 집합을 생성해요.
Kong Mesh는 이 결합된 태그 집합을 기준으로 정책을 매칭해요.
kuma.io/service=edge-gateway_default_svc
리스너 태그: vhost=foo.example.com
결합된 태그: kuma.io/service=edge-gateway_default_svc,vhost=foo.example.com
kuma.io/service=edge-gateway_default_svc
리스너 태그: kuma.io/service=example,domain=example.com
결합된 태그: kuma.io/service=example,domain=example.com
kuma.io/service=edge_default_svc,location=us
리스너 태그: version=2
결합된 태그: kuma.io/service=edge_default_svc,location=us,version=2
TLS 종료
HTTPS 프로토콜을 지정하고 서버 인증서 구성을 제공하면 게이트웨이에서 TLS 세션을 종료할 수 있어요. 아래 예제에서 게이트웨이는 포트 8443에서 리스닝하며 TLS 세션을 종료해요:
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: edge-gateway
spec:
selectors:
- match:
kuma.io/service: edge-gateway_default_svc
conf:
listeners:
- port: 8443
protocol: HTTPS
hostname: foo.example.com
tls:
mode: TERMINATE
certificates:
- secret: foo-example-com-certificate
tags:
name: foo.example.com
Universal
type: MeshGateway
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
conf:
listeners:
- port: 8443
protocol: HTTPS
hostname: foo.example.com
tls:
mode: TERMINATE
certificates:
- secret: foo-example-com-certificate
tags:
name: foo.example.com
서버 인증서는 Kong Mesh 데이터 소스 참조를 통해 제공돼요. 여기서는 서버 인증서와 그에 대응하는 프라이빗 키를 모두 담고 있어야 하는 시크릿을 가리켜요.
서버 인증서 시크릿
TLS 서버 인증서 시크릿은 Kong Mesh 데이터 소스(파일, Kong Mesh 시크릿, 또는 인라인 데이터일 수 있어요)에 담긴 PEM 객체들의 모음이에요.
최소한 프라이빗 키와 그에 대응하는 TLS 서버 인증서는 반드시 있어야 해요. CA 인증서 체인이 함께 있을 수도 있지만, 그런 경우 서버 인증서가 시크릿 안에서 첫 번째 인증서여야 해요.
Kong Mesh 게이트웨이는 RSA와 ECDSA 서버 인증서를 모두 서빙하는 기능을 지원해요.
이 기능을 사용하려면 서버 인증서 시크릿 두 개를 생성한 뒤, 둘 다 리스너 TLS 구성에 제공하세요.
kumactl 도구는 간단한 자체 서명된 TLS 서버 인증서 생성을 지원해요:
Kubernetes
apiVersion: v1
kind: Secret
metadata:
name: foo-example-com-certificate
namespace: kong-mesh-system
labels:
kuma.io/mesh: default
data:
value: "$(kumactl generate tls-certificate --type=server --hostname=foo.example.com --key-file=- --cert-file=- | base64 -w0)"
type: system.kuma.io/secret
Universal
type: Secret
mesh: default
name: foo-example-com-certificate
data: $(kumactl generate tls-certificate --type=server --hostname=foo.example.com --key-file=- --cert-file=- | base64 -w0)
크로스 메시
Mesh 추상화를 사용하면 자체 CA를 갖춘 일종의 서브 메시 안에 서비스를 캡슐화하고 격리할 수 있어요.
크로스 메시 MeshGateway를 사용하면 MeshHTTPRoute 리소스로 API를 정의해서 한 메시의 서비스를 다른 메시에 노출할 수 있어요.
모든 트래픽은 mTLS로 보호되는 Kong Mesh 데이터 플레인 안에 머물러요.
크로스 메시 통신에 참여하는 모든 메시는 mTLS가 활성화되어 있어야 해요.
MeshGateway 리스너에서 크로스 메시 기능을 활성화하려면 crossMesh 속성을 설정하세요:
Kubernetes
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: cross-mesh-gateway
labels:
kuma.io/mesh: default
spec:
selectors:
- match:
kuma.io/service: cross-mesh-gateway_default_svc
conf:
listeners:
- port: 8080
protocol: HTTP
crossMesh: true
hostname: default.mesh
Universal
type: MeshGateway
mesh: default
name: cross-mesh-gateway
selectors:
- match:
kuma.io/service: cross-mesh-gateway
conf:
listeners:
- port: 8080
protocol: HTTP
crossMesh: true
hostname: default.mesh
크로스 메시 호스트네임
리스너에 hostname 값이 포함되어 있으면, 크로스 메시 리스너는 모든 메시에서 이 hostname과 port로 접근할 수 있어요.
위 예제에서 URL은 http://default.mesh:8080이에요.
그렇지 않으면 internal.<gateway-name>.<mesh-of-gateway-name>.mesh 호스트로 접근할 수 있어요.
아웃바운드
투명 프록시가 설정되어 있지 않다면, 리스너에 접근하고 싶을 때 Dataplane 객체에 해당 리스너를 아웃바운드로 명시적으로 추가해야 해요:
outbound:
- port: 8080
tags:
kuma.io/service: cross-mesh-gateway
kuma.io/mesh: default
제한 사항
-
지원되는 유일한
protocol은HTTP예요. 서비스 간 트래픽과 마찬가지로, 게이트웨이로 향하는 모든 트래픽은 mTLS로 보호되지만 메시 안의 애플리케이션에는 HTTP 트래픽으로 보여요. -
crossMesh: true인MeshGateway의selectors에는 항목을 하나만 둘 수 있어요.
멀티 존
멀티 존 배포에서는 MeshGateway 리소스를 글로벌 컨트롤 플레인에서 생성해야 해요. 자세한 내용은 내장 게이트웨이를 참고하세요.
스키마
{
"properties": {
"selectors": {
"items": {
"$ref": "#/definitions/kuma.mesh.v1alpha1.Selector"
},
"type": "array",
"description": "Selectors is a list of selectors that are used to match builtin gateway dataplanes that will receive this MeshGateway configuration."
},
"tags": {
"additionalProperties": {
"type": "string"
},
"type": "object",
"description": "Tags is the set of tags common to all of the gateway's listeners. This field must not include a `kuma.io/service` tag (the service is always defined on the dataplanes)."
},
"conf": {
"$ref": "#/definitions/kuma.mesh.v1alpha1.MeshGateway.Conf",
"additionalProperties": true,
"description": "The desired configuration of the MeshGateway."
}
},
"additionalProperties": true,
"type": "object",
"title": "Mesh Gateway",
"description": "MeshGateway is a virtual proxy. Each MeshGateway is bound to a set of builtin gateway dataplanes. Each builtin dataplane instance can host exactly one Gateway proxy configuration. Gateway aligns with the Kubernetes Gateway API. See that spec for detailed documentation."
}
관련 리소스
더 알아보기 (Learn more)
- 내장 게이트웨이의 기본 개념과 동작 방식을 먼저 확인하고 싶다면 — built-in gateway
- 내장 게이트웨이를 처음부터 직접 설정해보는 실습이 필요하다면 — Add a built-in gateway
- 리스너 구성 다음 단계인 라우팅 규칙 설정 방법이 궁금하다면 — Configuring built-in routes
- 게이트웨이 없이 트래픽을 투명하게 가로채는 방식과 비교해보고 싶다면 — transparent proxy