TLS 마이그레이션
TLS 마이그레이션 (TLS Migration)
이 마이그레이션 예제는 앞선 HTTP 마이그레이션 예제를 바탕으로 두 HTTP 라우트에 TLS 종료를 추가해요. 간단히 하기 위해 productpage로 가는 두 번째 라우트는 생략했어요.
출처: TLS Migration
본문
이 마이그레이션 예제는 앞선 HTTP 마이그레이션 예제를 바탕으로 두 HTTP 라우트에 TLS 종료를 추가해요. 간단히 하기 위해 productpage로 가는 두 번째 라우트는 생략했어요.
Ingress 구성 검토하기 (Review Ingress Configuration)
예시 Ingress 정의는 tls-ingress.yaml에서 찾을 수 있어요.
# TLS ingress example, requires the below two applications
# https://raw.githubusercontent.com/istio/istio/release-1.11/samples/bookinfo/platform/kube/bookinfo.yaml
# https://github.com/GoogleCloudPlatform/microservices-demo
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tls-ingress
namespace: default
spec:
ingressClassName: cilium
rules:
- host: hipstershop.cilium.rocks
http:
paths:
- backend:
service:
name: productcatalogservice
port:
number: 3550
path: /hipstershop.ProductCatalogService
pathType: Prefix
- backend:
service:
name: currencyservice
port:
number: 7000
path: /hipstershop.CurrencyService
pathType: Prefix
- host: bookinfo.cilium.rocks
http:
paths:
- backend:
service:
name: details
port:
number: 9080
path: /details
pathType: Prefix
- backend:
service:
name: productpage
port:
number: 9080
path: /
pathType: Prefix
tls:
- hosts:
- bookinfo.cilium.rocks
- hipstershop.cilium.rocks
secretName: demo-cert
이 예제는:
- 포트 443의 HTTPS 트래픽을 수신해요.
- Secret demo-cert의 TLS 인증서와 키를 사용해
hipstershop.cilium.rocks와bookinfo.cilium.rocks호스트 이름에 대한 TLS를 종료해요. - URI 접두사
/hipstershop.ProductCatalogService가 있는hipstershop.cilium.rocks호스트 이름에 대한 HTTPS 요청을 productcatalogservice Service로 라우팅해요. - URI 접두사
/hipstershop.CurrencyService가 있는hipstershop.cilium.rocks호스트 이름에 대한 HTTPS 요청을 currencyservice Service로 라우팅해요. - URI 접두사
/details가 있는bookinfo.cilium.rocks호스트 이름에 대한 HTTPS 요청을 details Service로 라우팅해요. - 다른 접두사가 있는
bookinfo.cilium.rocks호스트 이름에 대한 HTTPS 요청을 productpage Service로 라우팅해요.
동등한 Gateway 구성 만들기 (Create Equivalent Gateway Configuration)
동등한 TLS 종료 구성을 만들려면 다음을 고려해주세요:
-
TLS 종료 (TLS Termination)
-
Ingress: Ingress 리소스는 Kubernetes Secret에 TLS 인증서와 키가 저장되는 TLS 섹션을 통해 TLS 종료를 지원해요.
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: tls-ingress namespace: default [...] spec: tls: - hosts: - bookinfo.cilium.rocks - hipstershop.cilium.rocks secretName: demo-cert -
Gateway API: Gateway API에서 TLS 종료는 Gateway 리스너의 속성이에요. Ingress와 마찬가지로 TLS 인증서와 키도 Secret에 저장돼요.
apiVersion: gateway.networking.k8s.io/v1beta1 kind: Gateway metadata: name: tls-gateway spec: gatewayClassName: cilium listeners: - name: bookinfo.cilium.rocks protocol: HTTPS port: 443 hostname: "bookinfo.cilium.rocks" tls: certificateRefs: - kind: Secret name: demo-cert - name: hipstershop.cilium.rocks protocol: HTTPS port: 443 hostname: "hipstershop.cilium.rocks" tls: certificateRefs: - kind: Secret name: demo-cert
-
-
호스트 헤더 기반 라우팅 규칙 (Host-header-based Routing Rules)
-
Ingress: Ingress API는 host라는 용어를 사용해요. Ingress에서는 각 호스트에 별도의 라우팅 규칙이 있어요.
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: tls-ingress namespace: default spec: ingressClassName: cilium rules: - host: hipstershop.cilium.rocks http: paths: - backend: service: name: productcatalogservice port: number: 3550 path: /hipstershop.ProductCatalogService pathType: Prefix -
Gateway API: Gateway API는 hostname이라는 용어를 사용해요. 호스트 헤더 기반 라우팅 규칙은 HTTPRoute의 호스트 이름에 매핑돼요. HTTPRoute에서 라우팅 규칙은 모든 호스트 이름에 적용돼요.
-
HTTPRoute의 호스트 이름은 Gateway 리스너의 호스트 이름과 일치해야 해요. 그렇지 않으면 리스너가 일치하지 않는 호스트 이름에 대한 라우팅 규칙을 무시해요.
--- apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute metadata: name: hipstershop-cilium-rocks namespace: default spec: hostnames: - hipstershop.cilium.rocks parentRefs: - name: cilium-gateway rules: - matches: - path: type: PathPrefix value: /hipstershop.ProductCatalogService backendRefs: - name: productcatalogservice port: 3550
-
동등한 Gateway 구성 검토하기 (Review Equivalent Gateway Configuration)
동등한 최종 Gateway와 HTTPRoute 정의는 tls-migration.yaml에서 찾을 수 있어요.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: cilium-gateway
namespace: default
spec:
gatewayClassName: cilium
listeners:
- hostname: hipstershop.cilium.rocks
name: hipstershop-cilium-rocks-http
port: 80
protocol: HTTP
- hostname: hipstershop.cilium.rocks
name: hipstershop-cilium-rocks-https
port: 443
protocol: HTTPS
tls:
certificateRefs:
- kind: Secret
name: demo-cert
- hostname: bookinfo.cilium.rocks
name: bookinfo-cilium-rocks-http
port: 80
protocol: HTTP
- hostname: bookinfo.cilium.rocks
name: bookinfo-cilium-rocks-https
port: 443
protocol: HTTPS
tls:
certificateRefs:
- kind: Secret
name: demo-cert
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: hipstershop-cilium-rocks
namespace: default
spec:
hostnames:
- hipstershop.cilium.rocks
parentRefs:
- name: cilium-gateway
rules:
- matches:
- path:
type: PathPrefix
value: /hipstershop.ProductCatalogService
backendRefs:
- name: productcatalogservice
port: 3550
- matches:
- path:
type: PathPrefix
value: /hipstershop.CurrencyService
backendRefs:
- name: currencyservice
port: 7000
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: bookinfo-cilium-rocks
namespace: default
spec:
hostnames:
- bookinfo.cilium.rocks
parentRefs:
- name: cilium-gateway
rules:
- matches:
- path:
type: PathPrefix
value: /details
backendRefs:
- name: details
port: 9080
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: productpage
port: 9080
리소스를 배포하고 HTTPS 요청이 서비스로 성공적으로 라우팅되는지 확인해보세요. 자세한 내용은 Gateway API HTTPS 예제를 참고해주세요.
더 알아보기 (Learn more)
- Ingress에서 Gateway로 마이그레이션 — 마이그레이션 개요
- HTTP 마이그레이션 예제 — HTTP 마이그레이션
- Gateway API (HTTPS) — HTTPS Gateway 예제
- Cilium Gateway API — Cilium Gateway API 개요