문제 설명
Kubernetes LoadBalancer에 TSL을 추가하는 동시에 컨테이너로 수명이 긴 TCP 연결 전달도 지원합니다. (Adding TSL to a Kubernetes LoadBalancer while also supporting forwarding a long lived TCP connection to a container)
백엔드 서비스를 GKE에 배포해야 합니다. 이 백엔드 서비스는 REST API와 여러 IoT 장치에서 사용할 TCP 서버로 구성됩니다. Google Kubernetes Engine 문서의 자습서에 따라 이를 달성하는 다음 서비스를 배포할 수 있었습니다.
apiVersion: v1
kind: Service
metadata:
name: my‑service
spec:
type: LoadBalancer
selector:
app: my‑backend‑app
ports:
‑ name: http
protocol: TCP
port: 80
targetPort: 8080
‑ name: https
protocol: TCP
port: 443
targetPort: 8080
‑ name: my‑tcp‑service
protocol: TCP
port: 2222
targetPort: 2222
위 구성의 문제는 REST API에 대해 TSL을 설정할 수 없다는 것입니다. Kubernetes에서 TSL을 설정하기 위해 찾은 모든 리소스는 Ingress를 가리키며 시도하는 동안 Ingress가 일종의 HTTP 프록시이므로(이해하는 한) 내 TCP 서버에서 Ingress가 작동하지 않는다는 것을 발견했습니다.
Ingress 없이 LoadBalancer에서 직접 TSL(HTTPS)을 설정할 수 있는 방법이 있습니까(Google 관리 인증서가 선호됨)? REST API에는 Ingress를, TCP 서버에는 다른 것을 사용해야 합니까?
참조 솔루션
방법 1:
Service type LoadBalancer is strictly a layer 4 service, thus it is impossible to have SSL termiantion happen on the LB. Traffic will be forwarded to your pods and SSL termination will need to occur there. Either that or you will need to have a proxy receive traffic and terminate TLS before forwarding the traffic to your application.
The ingress is currently the only option to use for Google‑managed certificates. You are correct that it uses HTTP proxy to terminate the requests. If you can arrange to have all requests come using different URLs, you could use a single Ingress, even for the TCP service (the front end would still be 443, but you can forward requests to port 2222).
The best option, though, would be to use the Ingress w/ managed certs for the HTTP(S) services and use the LoadBalancer service for the TCP service.