최근 k8s에 Istio를 적용하는도중 Service가 동작하지 않는 이슈를 발견했다. 웃긴게 curl로 http트래픽을 보내면 정상적으로 작동하는데 https로 보내면 작동하지 않았다.

위처럼 http로 접근하면 https로 redirect하는데 원인을 찾느라 한참 헤맸다.
알고보니 Envoy/istio는 x-forwarded-proto, x-forwared-for를 기본적으로 제거해 버린다. 방법은 EnvoyFilter에다 filterConfig를 추가하면된다
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: redirect-filter-ef
namespace: istio-system
spec:
configPatches:
- applyTo: NETWORK_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: envoy.http_connection_manager
portNumber: 443
patch:
operation: MERGE
value:
typed_config:
'@type': type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
use_remote_address: true
xff_num_trusted_hops: 2
여기서 핵심은 use_remote_address: true 속성이다. 그리고 xff_num_trusted_hops: 2에서 실제 클라이언트 IP를 얻을 수 있다.
참고자료들...
https://discuss.istio.io/t/trying-to-issue-redirect-with-envoyfilter/5981/3
Trying to issue redirect with EnvoyFilter
@xring - Any idea on this? I see in a different thread you’ve been down this path.
discuss.istio.io
https://aidanbae.github.io/code/devops/k8s/header/
envoy와 x-forwarded-proto 헤더 이슈
envoy와 x-forwarded-proto 헤더 이슈 - 아이단의 블로그
aidanbae.github.io
'Server Infra > Kubernetes' 카테고리의 다른 글
K8s Study DOIK - MySQL Operator for Kubernetes #2 (0) | 2022.06.05 |
---|---|
K8s Study DOIK - MySQL Operator for Kubernetes (0) | 2022.06.05 |
finalizers 제거기(Namespace Terminating) (0) | 2022.05.06 |
Docker Image 사이즈 튜닝 (0) | 2022.01.09 |
Docker Image Size 줄이기 다양한 팁들 (0) | 2022.01.09 |