Kubernetes Service(4): envoy config

  • kkumtree

2024-10-19T16:59:16+09:00

kans
envoy
proxy
kubernetes

์ •์ /๋™์  ์„ค์ •์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค.
traefik์„ ๋ง›๋ณผ๋•Œ๋Š”, ํ˜ธ๋˜๊ฒŒ ๋ฐ์ธ ๋ถ€๋ถ„์ธ๋ฐ envoy๋Š” ์ƒ๋Œ€์ ์œผ๋กœ ๋ช…๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค.

CloudNet@์—์„œ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” K8s Advanced Network Study(์ดํ•˜, KANS)๋ฅผ ํ†ตํ•ด ํ•™์Šตํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

1. Static Configuration

์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.

  • static_resources
    • listeners
    • clusters

(a) static_resources

envoy์˜ ์‹œ์ž‘๊ณผ ํ•จ๊ป˜, ์ •์ ์œผ๋กœ ์„ค์ •๋˜๋Š” ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๋ฅผ ํฌํ•จํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
์‹ค์ œ๋กœ envoy-demo.yaml ํŒŒ์ผ์„ ์—ด์–ด๋ณด๋ฉด ์ตœ์ƒ๋‹จ์— static_resources์ด ์„ ์–ธ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

static_resources:

  listeners:

(b) listeners

envoy-demo.yaml ํŒŒ์ผ ๊ธฐ์ค€,

  • socket_address: ๋ฆฌ์Šค๋„ˆ๋Š” ํฌํŠธ 10000์—์„œ ์ˆ˜์‹ ํ•˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • route_config: ๋ชจ๋“  ๊ฒฝ๋กœ์— ๋Œ€ํ•ด service_envoyproxy_io ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ผ์šฐํŒ…ํ•ฉ๋‹ˆ๋‹ค.
# cat envoy-demo.yaml | grep -A 30 -B 2 listeners
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.stdout
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.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

(c) clusters

envoy-demo.yaml ํŒŒ์ผ ๊ธฐ์ค€,

  • service_envoyproxy_io ํด๋Ÿฌ์Šคํ„ฐ๋Š” www.envoyproxy.io๋กœ ํ”„๋ก์‹œํ•ฉ๋‹ˆ๋‹ค.
  • TLS๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋ก์‹œํ•ฉ๋‹ˆ๋‹ค.
# cat envoy-demo.yaml | grep -A 18 clusters
  clusters:
  - name: service_envoyproxy_io
    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

2. xDS Comprenhensive Overview

๋™์  ์„ค์ •์œผ๋กœ ๋„˜์–ด๊ฐ€๊ธฐ ์ „์— envoy xDS๋ฅผ ์ดํ•ดํ•˜๊ณ ์ž ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

xDS ํ”„๋กœํ† ์ฝœ์„ ๊ตฌํ˜„ํ•˜๋Š” ํŒŒ์ผ๋“ค์„ ์‚ฌ์šฉํ•ด์„œ ๋™์  ๊ตฌ์„ฑ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

  • xDS ํ”„๋กœํ† ์ฝœ: envoy๊ฐ€ ๋™์  ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฒ€์ƒ‰ํ•  ๋•Œ ํ•ด๋‹น ์„œ๋น„์Šค์™€ API๋ฅผ xDS๋กœ ์ด์นญํ•ฉ๋‹ˆ๋‹ค.

(1) ๊ด€์ฐฐํ•  ํŒŒ์ผ๋ช…์„ ๋ช…์‹œํ•˜๊ฑฐ๋‚˜, (2) gRPC ์ŠคํŠธ๋ฆผ์„ ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜, ํ˜น์€ (3) REST-JSON API๋ฅผ ํด๋งํ•ด์„œ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. ์ด ์ค‘, 1ํ•ญ์˜ ๋ฐฉ๋ฒ•์„ ์ œ์™ธํ•˜๊ณ ๋Š” [DiscoveryResquest] Proto Payload์™€ ํ•จ๊ป˜ ์š”์ฒญ์„ ๋ณด๋‚ด์–ด ๊ตฌํ˜„๋ฉ๋‹ˆ๋‹ค.

  • ‘xDS’ ํ”„๋กœํ† ์ฝœ์˜ ๊ตฌ๋ถ„
SotW Incremental
separeted gRPC (a) (b)
single gRPC (c) (d)

SotW๋Š” Snapshot of the World๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ, ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๋กœ ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค.

(a) Basic xDS: ๋ชจ๋“  ๋ฆฌ์†Œ์Šค ์œ ํ˜•์— ๋Œ€ํ•œ, ๋ณ„๋„์˜ gRPC ์ŠคํŠธ๋ฆผ (b) Incremental xDS: ๊ฐ ๋ฆฌ์†Œ์Šค ์œ ํ˜•์— ๋Œ€ํ•œ ์ค‘๋ถ„, ๋ณ„๋„์˜ gRPC ์ŠคํŠธ๋ฆผ (c) Aggregated Discovery Service: ๋ชจ๋“  ๋ฆฌ์†Œ์Šค ์œ ํ˜•์— ๋Œ€ํ•œ, ๋‹จ์ผ gRPC ์ŠคํŠธ๋ฆผ (d) Incremental ADS: ๊ฐ ๋ฆฌ์†Œ์Šค ์œ ํ˜•์— ๋Œ€ํ•œ ์ค‘๋ถ„, ๋‹จ์ผ gRPC ์ŠคํŠธ๋ฆผ

๋ฌธ์„œ๋ฅผ ๋ณด๊ณ , ์„ ๋ช…ํ•˜๊ฒŒ ์ดํ•ด๊ฐ€ ์˜ค์ง€ ์•Š์•„ ๋งคํŠธ๋ฆญ์Šค๋ฅผ ๊ตฌ์„ฑํ–ˆ๋Š”๋ฐ๋„ ๋ญ”๊ฐ€ ๊ฐธ์›ƒํ•ฉ๋‹ˆ๋‹ค.

์—ฌํ•˜๊ฐ„, ์ฆ๋ถ„์„ ์‚ฌ์šฉํ•˜๋ฉด ์ด์ „ ์ƒํƒœ์™€ ์ƒ๋Œ€ ๋ธํƒ€์—๋งŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
gRPC ๋‹จ์ผ ์ŠคํŠธ๋ฆผ์€ ์ตœ์ข… ์ผ๊ด€์„ฑ(๋ฉฑ๋“ฑ์„ฑ?) ๋ชจ๋ธ์„ ์ œ๊ณตํ•˜๊ณ , ๋‹ค์ค‘ ์ŠคํŠธ๋ฆผ์€ ๋ฆฌ์†Œ์Šค์˜ lazy loading์— ๋Œ€์‘ํ•  ๋ฉ”์ปค๋‹ˆ์ฆ˜์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
์•ผ ์ด๊ฑฐ Firehose…. ์Œ ์•„์ง๋„ ์ข€ ๋ชจํ˜ธํ•ฉ๋‹ˆ๋‹ค

3. Dynamic Configuration (from filesystem)

Runtime ๊ฐ’ ๋Ÿฐํƒ€์ž„ ์„ค๋ช…์ด ๋ณ„๋„๋กœ ์žˆ๋Š”๋ฐ ์ข€ ๋‚œํ•ดํ•˜๋„ค์š”.

์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.

  • node : ํ”„๋ก์‹œ ์„œ๋ฒ„ ์‹๋ณ„
  • dynamic_resources : ๋™์  ๊ตฌ์„ฑ์˜ ์œ„์น˜๋ฅผ ๋ช…์‹œ
    • listeners
    • clusters

์•„๋ž˜์™€ ๊ฐ™์ด, ๋ฐ๋ชจ ํŒŒ์ผ์„ ๋ฐ›์•„๋ด…์‹œ๋‹ค.

curl -O https://www.envoyproxy.io/docs/envoy/latest/_downloads/9a41bc513e17e885884b3deebf435d2a/envoy-dynamic-filesystem-demo.yaml

(a) node

๋ฐ˜๋“œ์‹œ cluster์™€ id๋ฅผ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

# cat envoy-dynamic-filesystem-demo.yaml | grep -A 2 node:
node:
  cluster: test-cluster
  id: test-id

(b) dynamic_resources

์˜ˆ์ œ์—์„œ๋Š” LDS์™€ CDS ๋ฐ๋ชจํŒŒ์ผ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

curl -O https://www.envoyproxy.io/docs/envoy/latest/_downloads/5cf56125ff834c0e2f21f71e1e8916f2/envoy-dynamic-lds-demo.yaml
curl -O https://www.envoyproxy.io/docs/envoy/latest/_downloads/92bba5b0c48a649b4bc8663000cd097a/envoy-dynamic-cds-demo.yaml
  • listeners: envoy-dynamic-lds-demo.yaml

ํฌํŠธ 10000์—์„œ HTTP ๋ฆฌ์Šค๋„ˆ๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.
๋ชจ๋“  ๋„๋ฉ”์ธ๊ณผ ๊ฒฝ๋กœ๋Š” service_envoyproxy_io ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ผ์šฐํŒ…ํ•ฉ๋‹ˆ๋‹ค.
host ํ—ค๋”๋Š” www.envoyproxy.io๋กœ ๋ฎ์—ฌ์”๋‹ˆ๋‹ค.

# cat envoy-dynamic-lds-demo.yaml 
resources:
- "@type": type.googleapis.com/envoy.config.listener.v3.Listener
  name: listener_0
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 10000
  filter_chains:
  - filters:
    - name: envoy.http_connection_manager
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
        stat_prefix: ingress_http
        http_filters:
        - name: envoy.router
          typed_config:
            "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
        route_config:
          name: local_route
          virtual_hosts:
          - name: local_service
            domains:
            - "*"
            routes:
            - match:
                prefix: "/"
              route:
                host_rewrite_literal: www.envoyproxy.io
                cluster: example_proxy_cluster
  • clusters: envoy-dynamic-cds-demo.yaml

example_proxy_cluster ํด๋Ÿฌ์Šคํ„ฐ๋Š” www.envoyproxy.io๋กœ TLSํ”„๋ก์‹œํ•ฉ๋‹ˆ๋‹ค.

# cat envoy-dynamic-cds-demo.yaml
resources:
- "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
  name: example_proxy_cluster
  type: STRICT_DNS
  typed_extension_protocol_options:
    envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
      "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
      explicit_http_config:
        http2_protocol_options: {}
  load_assignment:
    cluster_name: example_proxy_cluster
    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

4. Dynamic Configuration (from Control Plane)

์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ์˜ ๊ตฌ์„ฑ์„ envoy์—๊ฒŒ ์ „๋‹ฌํ•˜๋„๋ก ์„ค์ •ํ•ด์•ผํ•˜๊ธฐ์— ๋ญ”๊ฐ€ ๋” ๊ธธ๊ฒŒ ์จ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋•Œ, ์ปจํŠธ๋กคํ”Œ๋ ˆ์ธ์€ Envoy API์™€ ํ˜ธํ™˜๋˜๋Š” Gloo ๋ฐ Istio ๋“ฑ์„ ์ง€์นญํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์€ ๊ตฌ์„ฑ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

  • node : ๊ณ ์œ ํ•œ ํ”„๋ก์‹œ ์„œ๋ฒ„ ์‹๋ณ„
  • dynamic_resources : ๋™์ ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•ด์•ผํ•˜๋Š” ๊ตฌ์„ฑ์„ envoy์—๊ฒŒ ๋ช…์‹œ
  • static_resources : ๊ฐ€์ ธ์˜ฌ ๊ตฌ์„ฑ์˜ ์œ„์น˜๋ฅผ envoy์—๊ฒŒ ๋ช…์‹œ

์˜ˆ์ œ์—์„œ ์‚ฌ์šฉํ•  ๋ฐ๋ชจ ํŒŒ์ผ์„ ๋ฐ›์•„๋ด…๋‹ˆ๋‹ค.

curl -O https://www.envoyproxy.io/docs/envoy/latest/_downloads/fe2234c3a6762bdffb5300e299973700/envoy-dynamic-control-plane-demo.yaml
  • node: 3-a์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
  • dynamic_resources : ๋™์  ๊ตฌ์„ฑ๊ณผ ์ด ์—…๋ฐ์ดํŠธ๋ฅผ ์—ฐ๊ฒฐํ•  cluster๋ฅผ ๋ช…์‹œํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ์˜ˆ์‹œ์—์„œ๋Š” ๊ฐ xDS ์œ ํ˜•์˜ ์„ค์ •์— ์˜ํ•ด ๊ตฌ์„ฑ์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.

# cat envoy-dynamic-control-plane-demo.yaml | grep -A 2 dynamic_resources:
dynamic_resources:
  ads_config:
    api_type: GRPC
    grpc_services:
    - envoy_grpc:
        cluster_name: xds_cluster
  cds_config:
    ads: {}
  lds_config:
    ads: {}
  • static_resources : (๋ง์ด ์ข€ ์ด์ƒํ•˜๊ธด ํ•œ๋ฐ) ๋™์ ๊ตฌ์„ฑ์„ ๊ฐ€์ ธ์˜ฌ ๊ณณ์„ ๋ช…์‹œํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ์˜ˆ์‹œ์—์„œ๋Š”, http://my-controle-plane:18000์—์„œ ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ์„ ์ฐพ๋„๋ก xds_cluster ์— ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

# cat envoy-dynamic-control-plane-demo.yaml | grep -A 17 static_resources:
static_resources:
  clusters:
  - type: STRICT_DNS
    typed_extension_protocol_options:
      envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
        "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
        explicit_http_config:
          http2_protocol_options: {}
    name: xds_cluster
    load_assignment:
      cluster_name: xds_cluster
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: my-control-plane
                port_value: 18000

kkumtree

plumber for infra

kkumtree

Source code on GitHub

ยฉ 2025 kkumtree and contributors All rights reserved.
Licensed under
CC BY-NC-ND 4.0