0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Envoyリバースプロキシ入門

Last updated at Posted at 2025-10-01

Envoyとは

Envoy Proxyは、オープンソースのエッジおよびサービスプロキシであり、マイクロサービスベースのアーキテクチャにおけるネットワークトラフィックを管理するために設計されています。現在では多くのクラウドネイティブ環境において中核コンポーネントとなっており、主にレイヤー7(HTTP)で動作しますが、より低レベルのプロトコルも処理できるため、様々なユースケースに対応可能です。リバースプロキシとして、Envoyは外部クライアントからのリクエストを受信し、内部サーバーに転送して応答を返します。クラウドネイティブ環境内では、ロードバランサー、APIゲートウェイ、またはサービスメッシュのコンポーネントとして機能します。

Envoy Proxy使ってみた

本記事ではシンプルにEnvoyをリバースプロキシとして利用してみます。

Envoy Proxyを利用するために、MacにEnvoyをインストールします。

brew install envoy

次にEnvoy Proxyの設定ファイルをenvoy.yamlに記述します。

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:
                  cluster: service_1

  clusters:
  - name: service_1
    type: LOGICAL_DNS
    # Comment out the following line to test on v6 networks
    dns_lookup_family: V4_ONLY
    load_assignment:
      cluster_name: service_1
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: localhost
                port_value: 8080

clustersにEnvoyがリクエストをルーティングするバックエンドサービス「service_1」を定義します。
localhost:8080でアプリケーションを起動しておきます。アプリケーションは前回の記事で作成したものを流用しました。

これで準備OKです。envoyを起動します。

envoy -c envoy.yaml

localhost:10000を利用してアプリケーションにアクセスします。

curl localhost:10000/books
[{"isbn":"9784422114361","title":"The Red Book","author":"C.G. ユング","publisher":"創元社","price":44000},{"isbn":"9784622012184","title":"ヨブへの答え","author":"C.G. ユング","publisher":"みすず書房","price":2420},{"isbn":"9784480093189","title":"横井小楠","author":"松浦 玲","publisher":"筑摩書房","price":1650}]

結果が返ってきました!

終わりに

Envoy Proxyの基本は以上です。今後はEnvoyの機能を拡張するための他のフィルターの統合や、より高度なユースケースについて掘り下げて行けたらと思います。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?