Ssoon

[7주차] Service Mesh : Envoy 본문

카테고리 없음

[7주차] Service Mesh : Envoy

구구달스 2024. 10. 15. 20:02
CloudNet@ 가시다님이 진행하는 쿠버네티스 네트워크 스터디 3기

✅ 기본환경

🧿 CloudFormation 스택을 배포합니다.

C:\Users\ssoon\KANS>aws cloudformation deploy --template-file kans-7w.yaml --stack-name mylab --parameter-overrides MyInstan
ceType=t3.xlarge KeyName=KANS_KEY SgIngressSshCidr=112.152.226.129/32 --region ap-northeast-2

Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - mylab

C:\Users\ssoon\KANS>aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIPAdd:PublicIpAddress,InstanceName:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters Name=instance-state-name,Values=running --output text
k3s-w1  3.36.120.74     running
testpc  54.180.251.50   running
k3s-s   3.38.214.243    running
k3s-w2  54.180.230.224  running

C:\Users\ssoon\KANS>ssh -i KANS_KEY.pem ubuntu@3.38.214.243
The authenticity of host '3.38.214.243 (3.38.214.243)' can't be established.
...
(⎈|default:N/A) root@k3s-s:~# kubectl get node -o wide
NAME     STATUS   ROLES                  AGE   VERSION        INTERNAL-IP      EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
k3s-s    Ready    control-plane,master   45m   v1.30.5+k3s1   192.168.10.10    <none>        Ubuntu 22.04.5 LTS   6.8.0-1015-aws   containerd://1.7.21-k3s2
k3s-w1   Ready    <none>                 45m   v1.30.5+k3s1   192.168.10.101   <none>        Ubuntu 22.04.5 LTS   6.8.0-1015-aws   containerd://1.7.21-k3s2
k3s-w2   Ready    <none>                 45m   v1.30.5+k3s1   192.168.10.102   <none>        Ubuntu 22.04.5 LTS   6.8.0-1015-aws   containerd://1.7.21-k3s2

🧿 testpc 접속 확인

C:\Users\ssoon\KANS>ssh -i KANS_KEY.pem ubuntu@54.180.251.50
The authenticity of host '54.180.251.50 (54.180.251.50)' can't be established.
...
root@testpc:~#

🧿 testps 에 Envoy 설치

root@testpc:~# wget -O- https://apt.envoyproxy.io/signing.key | sudo gpg --dearmor -o /etc/apt/keyrings/envoy-keyring.gpg
--2024-10-15 19:21:09--  https://apt.envoyproxy.io/signing.key
Resolving apt.envoyproxy.io (apt.envoyproxy.io)... 13.251.96.10, 52.74.166.77, 2406:da18:880:3800::c8, ...
Connecting to apt.envoyproxy.io (apt.envoyproxy.io)|13.251.96.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3158 (3.1K) [application/vnd.apple.keynote]
Saving to: ‘STDOUT’

-                              100%[====================================================>]   3.08K  --.-KB/s    in 0s

2024-10-15 19:21:10 (92.6 MB/s) - written to stdout [3158/3158]

root@testpc:~# echo "deb [signed-by=/etc/apt/keyrings/envoy-keyring.gpg] https://apt.envoyproxy.io focal main" | sudo tee /etc/apt/sources.list.d/envoy.list
deb [signed-by=/etc/apt/keyrings/envoy-keyring.gpg] https://apt.envoyproxy.io focal main

root@testpc:~# sudo apt-get update && sudo apt-get install envoy -y
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease
Get:5 https://apt.envoyproxy.io focal InRelease [7532 B]
Get:6 https://apt.envoyproxy.io focal/main amd64 Packages [17.7 kB]
Fetched 153 kB in 1s (132 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  envoy
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 73.2 MB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 https://apt.envoyproxy.io focal/main amd64 envoy amd64 1.31.2 [73.2 MB]
Fetched 73.2 MB in 5s (13.6 MB/s)
Selecting previously unselected package envoy.
(Reading database ... 66661 files and directories currently installed.)
Preparing to unpack .../envoy_1.31.2_amd64.deb ...
Unpacking envoy (1.31.2) ...
Setting up envoy (1.31.2) ...

You have installed the Envoy proxy server.

You can check your Envoy version by running the following in a terminal:

  $ envoy --version

Documentation for your version is available at:

  https://www.envoyproxy.io/docs

The Envoy project can be found at:

  https://github.com/envoyproxy/envoy

Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

root@testpc:~# envoy --version

envoy  version: cc4a75482810de4b84c301d13deb551bd3147339/1.31.2/Clean/RELEASE/BoringSSL

🧿 데모 config 적용

리스너 (Listeners):

  • 리스너는 외부에서 들어오는 트래픽을 수신하고 이를 적절한 서비스나 필터로 전달하는 역할을 합니다.
  • 이 경우, listener_0이라는 리스너가 정의되어 있으며, 0.0.0.0:10000에서 트래픽을 수신합니다. 즉, 모든 IP 주소(0.0.0.0)에서 포트 10000을 통해 들어오는 트래픽을 처리합니다.

필터 체인 (Filter Chains):

  • 리스너는 필터 체인을 사용하여 들어오는 트래픽을 처리합니다. 여기서는 http_connection_manager라는 네트워크 필터가 적용되어 있습니다. 이 필터는 HTTP 연결을 관리하고, 라우팅 및 로깅 등의 작업을 수행합니다.
  • 로그 설정 (Access Logs):
    • envoy.access_loggers.stdout를 사용하여 요청 로그를 표준 출력(stdout)으로 기록합니다.
  • HTTP 필터 (HTTP Filters):
    • envoy.filters.http.router는 요청을 라우팅하는 필터입니다.

라우트 설정 (Route Configuration):

  • 리스너의 라우트 설정은 들어오는 HTTP 요청을 처리하는 방식을 정의합니다. 여기서는 모든 요청(prefix: "/")이 www.envoyproxy.io로 전달됩니다.
  • domains: ["*"]는 모든 도메인에 대해 이 가상 호스트가 적용된다는 의미입니다.
  • 모든 경로에 대한 요청은 www.envoyproxy.io로 리다이렉트되며, 라우트는 service_envoyproxy_io 클러스터로 연결됩니다.

클러스터 (Clusters):

  • 클러스터는 Envoy가 외부 서비스를 어떻게 연결할지 정의합니다. 이 설정에서는 service_envoyproxy_io라는 이름의 클러스터가 정의되어 있으며, www.envoyproxy.io에 대한 트래픽을 처리합니다.
  • 클러스터 타입 (type: LOGICAL_DNS): LOGICAL_DNS 타입은 클러스터가 도메인 이름을 기반으로 서비스를 찾는다는 뜻입니다.
  • DNS 설정 (dns_lookup_family: V4_ONLY): IPv4 주소만 사용하여 DNS 조회를 합니다.
  • TLS 설정 (Transport Socket): 이 클러스터는 TLS를 사용하여 www.envoyproxy.io에 안전하게 연결됩니다.

Envoy 구성은 10000번 포트에서 들어오는 모든 HTTP 요청을 받아서, 이를 www.envoyproxy.io로 전달하는 간단한 프록시 역할을 합니다. service_envoyproxy_io 클러스터는 TLS를 사용해 안전한 연결을 보장하며, IPv4를 통해 DNS 조회를 수행합니다.

root@testpc:~# curl -O https://www.envoyproxy.io/docs/envoy/latest/_downloads/92dcb9714fb6bc288d042029b34c0de4/envoy-demo.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1757  100  1757    0     0   2724      0 --:--:-- --:--:-- --:--:--  2724
root@testpc:~# cat envoy-demo.yaml
static_resources:

  listeners:
  - name: listener_0	#첫 번째 리스너
    address:
      socket_address:
        address: 0.0.0.0	#모든 IP 주소에서 요청을 수신
        port_value: 10000	#이 포트에서 요청을 수신
        
    filter_chains:	#리스너가 요청을 처리하는 방식을 정의
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager	#HTTP 연결 관리 필터의 타입을 정의
          stat_prefix: ingress_http	#HTTP 요청 통계의 접두사
          access_log:	#요청 로그를 기록하는 설정
          - name: envoy.access_loggers.stdout
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog	#표준 출력에 로그를 기록하는 설정
          http_filters:	#HTTP 요청을 처리하는 필터를 설정
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router	#라우터 필터의 타입을 정의
          route_config:	#HTTP 요청의 라우팅 규칙을 정의
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]	#모든 도메인에 대해 이 가상 호스트가 적용
              routes:	#요청을 처리하는 라우팅 규칙을 정의
              - match:
                  prefix: "/"	#모든 요청 경로에 대해 매칭
                route:	#매칭된 요청이 전달될 클러스터와 호스트 재작성 설정을 정의
                  host_rewrite_literal: www.envoyproxy.io	#모든 요청의 호스트를 이 값으로 변경
                  cluster: service_envoyproxy_io	#요청을 이 클러스터로 라우팅

  clusters:
  - name: service_envoyproxy_io
    type: LOGICAL_DNS	#DNS를 사용하여 클러스터의 엔드포인트를 동적으로 확인하는 타입
    # Comment out the following line to test on v6 networks
    dns_lookup_family: V4_ONLY	# IPv4 주소만 사용하도록 설정
    load_assignment:	#클러스터에 대한 엔드포인트 정보를 설정
      cluster_name: service_envoyproxy_io
      endpoints:	#클러스터에 연결할 수 있는 엔드포인트를 정의
      - lb_endpoints:	#로드 밸런서 엔드포인트를 설정
        - endpoint:	#개별 엔드포인트를 정의
            address:	#엔드포인트의 주소를 정의
              socket_address:
                address: www.envoyproxy.io	#이 도메인 주소로 요청을 보냅니다.
                port_value: 443	#HTTPS 요청을 처리하는 포트
    transport_socket:	#엔드포인트와의 연결에 사용할 전송 소켓을 정의
      name: envoy.transport_sockets.tls
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext	#TLS 설정의 타입을 정의
        sni: www.envoyproxy.io	#TLS 연결 시 사용할 SNI(Server Name Indication) 정보를 설정
        
 root@testpc:~# envoy -c envoy-demo.yaml
[2024-10-15 19:39:04.798][3312][info][main] [source/server/server.cc:426] initializing epoch 0 (base id=0, hot restart version=11.104)
[2024-10-15 19:39:04.798][3312][info][main] [source/server/server.cc:428] statically linked extensions:
[2024-10-15 19:39:04.798][3312][info][main] [source/server/server.cc:430]   envoy.tracers.opentelemetry.samplers: envoy.tracers.opentelemetry.samplers.always_on, envoy.tracers.opentelemetry.samplers.dynatrace
....

🧿 Envoy Proxy  정보 확

  • 포트 10000: 두 개의 인스턴스가 실행 중입니다. envoy 프로세스가 이 포트를 통해 요청을 수신합니다.
root@testpc:~# ss -tnlp
State   Recv-Q  Send-Q   Local Address:Port     Peer Address:Port  Process
LISTEN  0       128            0.0.0.0:22            0.0.0.0:*      users:(("sshd",pid=705,fd=3))
LISTEN  0       4096     127.0.0.53%lo:53            0.0.0.0:*      users:(("systemd-resolve",pid=348,fd=14))
LISTEN  0       4096           0.0.0.0:10000         0.0.0.0:*      users:(("envoy",pid=3312,fd=25))
LISTEN  0       4096           0.0.0.0:10000         0.0.0.0:*      users:(("envoy",pid=3312,fd=24))
LISTEN  0       511                  *:80                  *:*      users:(("apache2",pid=2388,fd=4),("apache2",pid=2387,fd=4),("apache2",pid=2385,fd=4))
LISTEN  0       128               [::]:22               [::]:*      users:(("sshd",pid=705,fd=4))

🧿 접속 테스트

[ 터미널-1 ]

root@testpc:~# curl -s http://127.0.0.1:10000 | grep -o "<title>.*</title>"
<title>Envoy proxy - home</title>

 

[ 터미널-2]

[2024-10-15T10:41:24.472Z] "GET / HTTP/1.1" 200 - 0 15795 795 722 "-" "curl/7.81.0" "d2168932-976c-4b56-8b10-1feccb2d1a0e" "www.envoyproxy.io" "13.251.96.10:443"

root@testpc:~# echo -e "http://$(curl -s ipinfo.io/ip):10000"
http://54.180.251.50:10000


[ k3s-s ]

(⎈|default:N/A) root@k3s-s:~# curl -s http://192.168.10.200:10000 | grep -o "<title>.*</title>"
<title>Envoy proxy - home</title>


[ testpc ]

[2024-10-15T10:44:40.047Z] "GET / HTTP/1.1" 200 - 0 15795 767 697 "-" "curl/7.81.0" "c6c695ae-9778-4ac2-b87a-1e02efeb5b11" "www.envoyproxy.io" "52.74.166.77:443"

[ testpc ]

root@testpc:~# ss -tnp
State      Recv-Q      Send-Q            Local Address:Port             Peer Address:Port      Process
ESTAB      0           0                192.168.10.200:10000           112.152.71.99:60061      users:(("envoy",pid=3312,fd=43))
ESTAB      0           0                192.168.10.200:10000           112.152.71.99:60052      users:(("envoy",pid=3312,fd=22))
ESTAB      0           0                192.168.10.200:10000           112.152.71.99:60063      users:(("envoy",pid=3312,fd=41))
ESTAB      0           0                192.168.10.200:22              112.152.71.99:59835      users:(("sshd",pid=2760,fd=4),("sshd",pid=2678,fd=4))
ESTAB      0           60               192.168.10.200:22              112.152.71.99:60031      users:(("sshd",pid=3379,fd=4),("sshd",pid=3323,fd=4))
ESTAB      0           0                192.168.10.200:10000           112.152.71.99:60062      users:(("envoy",pid=3312,fd=39))
ESTAB      0           0                192.168.10.200:10000           112.152.71.99:60058      users:(("envoy",pid=3312,fd=37))
ESTAB      0           0                192.168.10.200:10000           112.152.71.99:60053      users:(("envoy",pid=3312,fd=34))

 

[ testpc ]

  • Envoy의 Admin API에 대한 주소를 설정합니다. 여기서 0.0.0.0은 모든 IP 주소에서 접근 가능하다는 의미이며, 9902는 Admin API가 리스닝할 포트 번호입니다.
root@testpc:~# cat <<EOT> envoy-override.yaml
admin:
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 9902
EOT
envoy -c envoy-demo.yaml --config-yaml "$(cat envoy-override.yaml)"
[2024-10-15 19:55:40.067][3418][info][main] [source/server/server.cc:426] initializing epoch 0 (base id=0, hot restart version=11.104)
...

  • envoy 관리페이지 접속 확인
root@testpc:~# echo -e "http://$(curl -s ipinfo.io/ip):9902"
http://54.180.251.50:9902


 

Comments