23
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EnvoyのGetting Startedをやってみた

Last updated at Posted at 2018-10-22

TL;DR

公式サンプル

docker pull envoyproxy/envoy:latest
docker run --rm -d -p 10000:10000 envoyproxy/envoy:latest
curl -v localhost:10000
  • curl
    • localhost:10000にcurlするとenvoy経由でgoogleに飛ばされることが確認出来る。
curl -I localhost:10000
HTTP/1.1 200 OK
date: Fri, 19 Oct 2018 10:27:05 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
server: envoy
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
set-cookie: 1P_JAR=2018-10-19-10; expires=Sun, 18-Nov-2018 10:27:05 GMT; path=/; domain=.google.com
set-cookie: NID=141=xxxxxxxxxxxxxxxxxxxx; expires=Sat, 20-Apr-2019 10:27:05 GMT; path=/; domain=.google.com; HttpOnly
alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"
accept-ranges: none
vary: Accept-Encoding
x-envoy-upstream-service-time: 111
transfer-encoding: chunked

以上

  • でおわるとあまりに何も無いので設定ファイルの内容を読み込んでみた.

設定ファイル

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address:
      protocol: TCP
      address: 127.0.0.1
      port_value: 9901
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 10000
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        config:
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match:
                  prefix: "/"
                route:
                  host_rewrite: www.google.com
                  cluster: service_google
          http_filters:
          - name: envoy.router
  clusters:
  - name: service_google
    connect_timeout: 0.25s
    type: LOGICAL_DNS
    # Comment out the following line to test on v6 networks
    dns_lookup_family: V4_ONLY
    lb_policy: ROUND_ROBIN
    hosts:
      - socket_address:
          address: google.com
          port_value: 443
    tls_context: { sni: www.google.com }
  • admin部分の解説

 admin:
   access_log_path: /tmp/admin_access.log
  address:
     socket_address: { address: 127.0.0.1, port_value: 9901 }
  • Envoyにはproxyと同時にadmin機能が提供されている。
  • adminにはweb guiとenvoyの状態を取得するapiがある。

Web GUI

image.png

  • admin機能にはcluster(Envoyからproxy出来る対象)の状況を見たり、Envoyを止めるなどの機能が提供されている。
    権限が強いのでアクセス制限された設定をするのが通常らしい。

  • access_log_path

  • adminにアクセスしたaccess_logを出力する箇所

  • 出力しない場合は /dev/null を入れれば良い

  • address

  • admin機能をlistenerするaddressを記載する

  • Getting Startedの場合はlocalからの9901しか許可されていないため、 container入ってからcurlするとadminサーバーの存在が動いていることが確認出来る。

root@9debcc6e7549:/# curl -I localhost:9901
HTTP/1.1 200 OK
content-type: text/html; charset=UTF-8
cache-control: no-cache, max-age=0
x-content-type-options: nosniff
date: Tue, 14 Aug 2018 02:01:08 GMT
server: envoy
transfer-encoding: chunked
 
root@9debcc6e7549:/# cat /tmp/admin_access.log
[2018-08-14T02:00:40.709Z] "GET / HTTP/1.1" 200 - 0 4389 0 - "172.17.0.2" "curl/7.47.0" "-" "localhost:9901" "-"
[2018-08-14T02:00:42.322Z] "GET / HTTP/1.1" 200 - 0 4389 0 - "172.17.0.2" "curl/7.47.0" "-" "localhost:9901" "-"
[2018-08-14T02:01:08.336Z] "HEAD / HTTP/1.1" 200 - 0 4389 0 - "172.17.0.2" "curl/7.47.0" "-" "localhost:9901" "-"
 static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address: { address: 0.0.0.0, port_value: 10000 }
      filter_chains:
      - filters:
        - name: envoy.http_connection_manager
          config:
            stat_prefix: ingress_http
            route_config:
              name: local_route
              virtual_hosts:
              - name: local_service
                domains: ["*"]
                routes:
                - match: { prefix: "/" }
                  route: { host_rewrite: www.google.com, cluster: service_google }
            http_filters:
            - name: envoy.router
    clusters:
    - name: service_google
     connect_timeout: 0.25s
      type: LOGICAL_DNS
    # Comment out the following line to test on v6 networks
     dns_lookup_family: V4_ONLY
      lb_policy: ROUND_ROBIN
      hosts: [{ socket_address: { address: google.com, port_value: 443 }}]
      tls_context: { sni: www.google.com }

設定ファイル

  • 環境変数は使えないっぽい。
  • Lyftはjinja (http://jinja.pocoo.org/) というtemplate使ってるみたい。
23
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?