๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”Ž Service Mesh

[Service Mesh] 2. Envoy Proxy

by Seongpyo Hong 2020. 12. 21.

Service Mesh ์•Œ์•„๋ณด๊ธฐ

  1. [Service Mesh] 1. Service Mesh๋ž€?
  2. [Service Mehs] 2. Envoy Proxy
  3. [Service Mesh] 3. Istio?
  4. [Service Mesh] 4. Istio Traffic Management (1) - Virtual Service & Destination Rule
  5. [Service Mesh] 5. Istio Traffic Managerment (2) - Gateway & Service Entry
  6. [Service Mesh] 6. Service Monitoring in Istio
  7. [Service Mesh] 7. Logging

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Service Mesh์—์„œ Sidecar๋กœ ์ฃผ๋กœ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” Envoy Proxy์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

Envoy?

Envoy๋Š” L7 ํ”„๋ก์‹œ๋กœ ํ˜„๋Œ€์˜ ์„œ๋น„์Šค ๊ธฐ๋ฐ˜ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์œ„ํ•ด ๋งŒ๋“ค์–ด์กŒ์Šต๋‹ˆ๋‹ค. Envoy๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜์—ฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ํˆฌ๋ช…ํ•œ ๋„คํŠธ์›Œํฌ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. 

Out of Process Architecture
Envoy๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์™€ ํ•จ๊ป˜ ์‹คํ–‰๋˜๋„๋ก ์„ค๊ณ„๋œ self-contained ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค. ๊ฐ Envoy๋Š” ํˆฌ๋ช…ํ•œ ๋„คํŠธ์›Œํฌ๋ฅผ ํ˜•์„ฑํ•˜๊ณ  ๊ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ Localhost๊ณผ ๋ฉ”์„ธ์ง€๋ฅผ ์ฃผ๊ณ ๋ฐ›์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋„คํŠธ์›Œํฌ ํ† ํด๋กœ์ง€์— ๋Œ€ํ•ด ์•Œ์ง€ ๋ชปํ•œ ์ƒํƒœ์ž…๋‹ˆ๋‹ค. Out of Process ์•„ํ‚คํ…์ฒ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์ ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Envoy๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์‚ฌ์šฉ๋œ ์–ธ์–ด์— ์ƒ๊ด€์—†์ด ๋™์ž‘ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  • Envoy๋Š” ๋น ๋ฅด๊ฒŒ ๋ฐฐํฌ๋˜๊ณ  ์—…๊ทธ๋ ˆ์ด๋“œ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

L3/L4 Filter Architecture
Envoy์˜ ํ•ต์‹ฌ์€ L3/L4 ๋„คํŠธ์›Œํฌ ํ”„๋ก์‹œ์ž…๋‹ˆ๋‹ค. ํ”Œ๋Ÿฌ๊ทธ์ธ ๋ฐฉ์‹์˜ ํ•„ํ„ฐ ์ฒด์ธ์„ ํ†ตํ•ด TCP/UDP ํ”„๋ก์‹œ ์ž‘์—…์„ ์ˆ˜ํ–‰ ๋ฐ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

HTTP L7 Filter Architecture
Envoy๋Š” L3/L4 ๊ณ„์ธต ์ด์™ธ์—๋„ L7 ๋„คํŠธ์›Œํฌ ํ”„๋ก์‹œ๋„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด QoS์™€ ๊ฐ™์€ ์ข€ ๋” ์„ธ๋ฐ€ํ•œ ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

HTTP/2 & gRPC
HTTP/2 ๋ฐ gRPC๋ฅผ ์ง€์›ํ•จ์œผ๋กœ์จ ์š”์ฒญ๊ณผ ์‘๋‹ต์„ ๋ฉ€ํ‹ฐํ”Œ๋ ‰์‹ฑํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Service Discovery & Dynamic Configuration
๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์— ๋Œ€ํ•œ ๋™์  ์„ค์ • ๋ฐ ์ด๋ฅผ ํ†ตํ•œ ์„œ๋น„์Šค ๋””์Šค์ปค๋ฒ„๋ฆฌ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. 


์ž‘๋™ ๋ฐฉ์‹

๋‹ค์Œ์œผ๋กœ ๋ฉ”์„ธ์ง€ ์ฒ˜๋ฆฌ ๊ตฌ์กฐ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Envoy๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ๋ฉ”์„ธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

Downstream โ‡’ Listener โ‡’ Filter โ‡’ Cluster(Upstream)
  • Downstream : Envoy์—๊ฒŒ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ํ˜ธ์ŠคํŠธ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
  • Listener : Downstream์—๊ฒŒ ์š”์ฒญ์„ ๋ฐ›๋Š” ๋ถ€๋ถ„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. Envoy๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ Listener์„ ๋…ธ์ถœํ•˜์—ฌ Downstream๊ณผ ์—ฐ๊ฒฐ๋ฉ๋‹ˆ๋‹ค.
  • Filter : ์ˆ˜์‹ ๋œ ๋ฉ”์‹œ์ง€์— ๋Œ€ํ•ด ๋ผ์šฐํŒ…, ํ”„๋กœํ† ์ฝœ ๋ณ€ํ™˜, ํ†ต๊ณ„ ์ƒ์„ฑ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ถ€๋ถ„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
  • Upstream : Envoy๊ฐ€ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ํ˜ธ์ŠคํŠธ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
  • Cluster : Upstream ํ˜ธ์ŠคํŠธ์˜ ๊ทธ๋ฃน์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

Envoy ์‹คํ–‰ (Docker)

Docker๋ฅผ ํ†ตํ•ด Envoy Proxy๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์‹คํ–‰์‹œ์ผœ ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Docker Image๋ฅผ ํ†ตํ•ด Envoy๋ฅผ ์‰ฝ๊ฒŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋จผ์ € Envoy Docker Image๋ฅผ Pull ๋ฐ›์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ, latest tag๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์œผ๋‹ˆ Envoy ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์—ฌ ํ•„์š”ํ•œ ํƒœ๊ทธ๋ช…์„ ์‚ฌ์šฉํ•˜์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

> docker pull envoyproxy/envoy:v1.16-latest

๋‹ค์Œ์œผ๋กœ Envoy ์‹คํ–‰์— ์‚ฌ์šฉ๋˜๋Š” envoy.yaml ํŒŒ์ผ์„ ํ™•์ธํ•ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address:
      protocol: TCP
      address: 0.0.0.0
      port_value: 9901
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        address: 0.0.0.0
        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
          stat_prefix: ingress_http
          access_log:
          - name: envoy.access_loggers.file
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
              path: /dev/stdout
          http_filters:
          - name: envoy.filters.http.router
          route_config:
            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
    connect_timeout: 30s
    type: LOGICAL_DNS
    # Comment out the following line to test on v6 networks
    dns_lookup_family: V4_ONLY
    load_assignment:
      cluster_name: service_envoyproxy_io
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: www.envoyproxy.io
                port_value: 443
    transport_socket:
      name: envoy.transport_sockets.tls
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
        sni: www.envoyproxy.io

๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค์ • ๋‚ด์šฉ์„ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

  • admin
    envoy admin ํŽ˜์ด์ง€ ์„ค์ •์œผ๋กœ address๋ฅผ ํ†ตํ•ด ์ ‘์† ๊ฐ€๋Šฅํ•œ IP๋ฅผ, port๋ฅผ ํ†ตํ•ด admin page์˜ port๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

docker๋ฅผ ํ†ตํ•ด ์‹คํ–‰ํ•  ๊ฒฝ์šฐ, 127.0.0.1์€ bridge network์˜ localhost๋ฅผ ์˜๋ฏธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ชจ๋“  IP๋ฅผ ํ—ˆ์šฉํ•˜๋Š” 0.0.0.0๋กœ ๋ณ€๊ฒฝํ•˜์˜€์Šต๋‹ˆ๋‹ค.

  • listeners
    ๋ฆฌ์Šค๋„ˆ๊ฐ€ ์ˆ˜์‹ ํ•  ํฌํŠธ์™€ ์ฃผ์†Œ์— ๋Œ€ํ•œ ์„ค์ •์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
  • filter_chains
    ์ˆ˜์‹ ํ•œ ๋ฉ”์„ธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•  filter์— ๋Œ€ํ•œ ์„ค์ •๊ฐ’์œผ๋กœ ํ˜„์žฌ ์„ค์ •๊ฐ’์€ / ๊ฒฝ๋กœ๋กœ ๊ฐ€๋Š” ๋ชจ๋“  ์š”์ฒญ์„ service_envoyproxy_io๋กœ ๋ผ์šฐํŒ…ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  • clusters
    envoy๊ฐ€ ์š”์ฒญ์„ ๋ณด๋‚ผ ํ˜ธ์ŠคํŠธ๋กœ ํ˜„์žฌ ์„ค์ •๊ฐ’์€ envoyproxy.com์œผ๋กœ ๋ผ์šฐํŒ… ํ•˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

Envoy Container ์‹คํ–‰

์œ„์—์„œ ์ ์šฉํ–ˆ๋˜ admin ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ ์šฉํ•œ ์„ค์ •ํŒŒ์ผ์„ ๋งˆ์šดํŠธํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ €๋Š” docker run์˜ -v ์˜ต์…˜์œผ๋กœ ๋งˆ์šดํŠธ๋ฅผ ์‹œ๋„ํ–ˆ์œผ๋‚˜ envoy์— ๋Œ€ํ•œ ์„ค์ •๊ฐ’ ์œ„์น˜๋ฅผ ์ฐพ๋Š” ๊ฒƒ์ด ๋ฒˆ๊ฑฐ๋กœ์›Œ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Dockerfile

FROM envoyproxy/envoy:v1.16-latest
COPY envoy.yaml /etc/envoy/envoy.yaml
RUN chmod go+r /etc/envoy/envoy.yaml

 

Image Build & Run

> docker build -t envoy:local .
> docker run --rm -d -p 10000:10000 -p 9901:9901 envoy:local

 

localhost:10000(Envoy Listener)์œผ๋กœ ์ ‘์†ํ•œ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์œ„์˜ ์„ค์ •์—์„œ /์œผ๋กœ ๋ณด๋‚ด์ง€๋Š” ๋ชจ๋“  ์š”์ฒญ์€ envoyproxy.io๋กœ ๋ณด๋‚ด๋„๋ก ์„ค์ •ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— envoyproxy.io ํ™ˆํŽ˜์ด์ง€๊ฐ€ ๋‚˜์˜จ ๋ชจ์Šต์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Envoy Proxy Test

localhost:9901(Envoy Admin)์— ์ ‘์†ํ•œ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Envoy Admin

 

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Service Mesh์—์„œ Sidecar Proxy๋กœ ์‚ฌ์šฉ๋˜๋Š” Envoy์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ Docker๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰์‹œ์ผœ ๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ๊ธ€์—์„œ๋Š” Service Mesh ํ”Œ๋žซํผ์ธ Istio์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 

์ฐธ๊ณ ์ž๋ฃŒ

  1. Istio๋กœ ์‹œ์ž‘ํ•˜๋Š” ์„œ๋น„์Šค ๋ฉ”์‹œ - ์—์ด์ฝ˜ ์ถœํŒ์‚ฌ
  2. Envoy Document

๋Œ“๊ธ€