Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Envoy Proxy가 어떻게 트래픽을 가로채는가? #9

Open
ByeongHunKim opened this issue Sep 21, 2024 · 5 comments
Open
Assignees
Labels
question Further information is requested Season1 Season1 Study
Milestone

Comments

@ByeongHunKim
Copy link
Owner

ByeongHunKim commented Sep 21, 2024

Question / 질문 내용

sidecar로 주입된 proxy container가 어떻게 트래픽을 가로채는 지 정확한 동작원리가 궁금합니다

Context / 상황 설명

강의에서 envoy를 소개할 때 질문에 대한 답변은 없었고 그냥 구조만 설명하네요

현재 이해하고 있는 부분

  1. Sidecar 주입
    istio-sidecar-injector에 의해 istio-proxy(Envoy) 컨테이너를 sidecar로 주입

  2. iptables 규칙 설정
    Pod 생성 시 istio-init이라는 init 컨테이너가 실행되어 iptables 규칙을 설정.
    이 규칙들은 Pod로 들어오고 나가는 모든 네트워크 트래픽을 istio-proxy로 리다이렉트 됨

  3. 트래픽 가로채기
    설정된 iptables 규칙에 의해 Pod로 들어오는 인바운드 트래픽은 15006 포트로, 아웃바운드 트래픽은 15001 포트로 리다이렉트

  4. 트래픽 처리
    istio-proxy는 가로챈 트래픽을 검사하고 Istio의 라우팅 규칙 등을 적용하여 적절히 처리. 인바운드 트래픽은 애플리케이션 컨테이너로 전달하고, 아웃바운드 트래픽은 대상 서비스로 라우팅

  5. 라우팅 규칙을 받아 트래픽이 어떻게 제어되는가(?)

What I've Tried / 시도한 방법
질문에 대한 답을 찾기 위해 시도해본 방법이 있다면 설명해주세요

자료를 찾고 있습니다

Resources / 관련 자료
질문과 관련된 문서, 링크, 코드 등이 있다면 여기에 첨부해주세요

image

출처: https://jimmysong.io/en/blog/beyond-istio-oss/

Additional context / 추가 사항
기타 추가적인 정보나 생각이 있다면 여기에 작성해주세요

@ByeongHunKim ByeongHunKim added the question Further information is requested label Sep 21, 2024
@ByeongHunKim ByeongHunKim added this to the Milestone1 milestone Sep 21, 2024
@ByeongHunKim ByeongHunKim added the Season1 Season1 Study label Sep 23, 2024
@ByeongHunKim
Copy link
Owner Author

ByeongHunKim commented Sep 23, 2024

netFilter :

Netfilter is a framework that allows to configure packet filtering, create NAT or port translation rules, and manage the traffic flow in the network.

iptables :

Iptables, on the other hand, is a user-space utility program that allows you to configure the IP packet filter rules of the Linux kernel firewall.

출처 : https://learnk8s.io/kubernetes-network-packets#:~:text=do%20they%20work%3F-,Intercepting%20and%20rewriting%20traffic%20with%20Netfilter%20and%20Iptables,-The%20service%20in

@ByeongHunKim ByeongHunKim changed the title [Question] Istio proxy container가 어떻게 트래픽을 가로채는가? [Question] Envoy Proxy 가 어떻게 트래픽을 가로채는가? Sep 25, 2024
@ByeongHunKim ByeongHunKim changed the title [Question] Envoy Proxy 가 어떻게 트래픽을 가로채는가? [Question] Envoy Proxy가 어떻게 트래픽을 가로채는가? Sep 25, 2024
@ByeongHunKim
Copy link
Owner Author

image

@ByeongHunKim
Copy link
Owner Author

ByeongHunKim commented Sep 26, 2024

@opp-13 @esc-beep

직접 조회한 명령어

nsenter명령어-설명

# istio-injection=enabled 상태 이후 proxy container 주입된 상태. 즉 istio-init container가 iptables 규칙 설정 완료
# pod/production-xxxxx  2/2     Running   0          5d15h

NODENAME=$(kubectl get pods production-xxxxx -o jsonpath="{.spec.nodeName}")

echo $NODENAME

# 해당 노드로 ssh 접속

CONTAINER_ID=$(kubectl get pod production-xxxxx -o jsonpath='{.status.containerStatuses[0].containerID}' | cut -d'/' -f3)

echo $CONTAINER_ID 

sudo crictl inspect $CONTAINER_ID

sudo nsenter -t $(sudo crictl inspect $CONTAINER_ID | jq -r .info.pid) -n iptables -L -t nat -v

해당 어플리케이션의 iptables 규칙

image

체인에 명시된 부분 확인

PREROUTING 체인:

  • 모든 인바운드 TCP 트래픽은 ISTIO_INBOUND 체인으로 전달
    • 이를 통해 pod로 들어오는 모든 트래픽을 Istio가 제어할 수 있게 되는 것 같네요

OUTPUT 체인:

  • 모든 아웃바운드 TCP 트래픽은 ISTIO_OUTPUT 체인으로 전달
    • 이를 통해 pod에서 나가는 트래픽을 위와 마찬가지로 Istio가 제어 가능

ISTIO_INBOUND 체인:

  • 특정 포트(15008, 15090, 15021, 15020)로 향하는 트래픽은 바로 RETURN. 이 포트들은 Istio 내부 통신에 사용되는 포트
    • 그 외의 트래픽은 ISTIO_IN_REDIRECT 체인으로 전달

ISTIO_IN_REDIRECT 체인:

  • 모든 트래픽을 15006 포트로 리다이렉트. 이 포트는 Envoy 프록시의 인바운드 리스너 포트! 위에 그림에 sidecar proxy container 가 15006 포트임

ISTIO_OUTPUT 체인:

  • 로컬호스트 트래픽은 즉시 RETURN
  • UID 1337(Envoy 프록시의 UID)로부터 발생한 트래픽인 것 같네요 ( 아직 잘 모르겠음 )
  • 로컬호스트로 향하는 트래픽은 RETURN
    • 나머지 트래픽은 ISTIO_REDIRECT 체인으로 전달

ISTIO_REDIRECT 체인:

  • 모든 트래픽을 15001 포트로 리다이렉트. 이 포트는 Envoy 프록시의 아웃바운드 리스너 포트

@ByeongHunKim
Copy link
Owner Author

ByeongHunKim commented Sep 26, 2024

This was referenced Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Season1 Season1 Study
Projects
Status: In Progress
Development

No branches or pull requests

3 participants