0
1

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によるTCPプロキシ

Last updated at Posted at 2023-10-12

はじめに

EnvoyによるTCP Proxyを構築する必要があったため、備忘録として記録します。
Dockerコンテナで構築します。

Envoyコンテナの設定

compose.yaml
version: '3'
services:
  envoy:
    container_name: envoy
    hostname: envoy
    image: envoyproxy/envoy:v1.27-latest
    ports:
      - "9901:9901"
      - "9000:9000"
    volumes:
      - ./envoy.yaml:/etc/envoy/envoy.yaml

  clickhouse:
    image: clickhouse/clickhouse-server:23.3.8.21
    container_name: clickhouse
    hostname: clickhouse
    restart: always

Envoyの設定

envoy.yaml
# Envoyの統計情報、メトリック情報が確認できる
admin:
  access_log_path: /dev/null
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 9901

# Listeners には、リクエストを受ける設定を書く
# Fillters には、どのようにリクエストを処理するかを書く
# Clusters には、リクエストの転送先を書く
static_resources:
  listeners:
    # Listenersの名前
    - name: test_listener
      address:
        socket_address:
          # コンテナなので0.0.0.0でリッスン
          address: 0.0.0.0
          # リッスンポートを指定
          port_value: 9000
      # Filter Chains and Filtersでリクエストの処理方法を定義
      filter_chains:
        - filters:
            # 利用するフィルターの種類
            - name: envoy.filters.network.tcp_proxy
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
                # モニタリング用途に使うメトリクス名のプレフィクス
                stat_prefix: tcp
                # リクエストを処理するクラスターの名前
                cluster: test_cluster
                # アクセスログの設定
                access_log:
                  - name: envoy.file_access_log
                    typed_config:
                      "@type": "type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog"
                      path: /dev/stdout
                      # ログをJSONフォーマットで整形
                      # https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage
                      # json_format:
                      #     "protocol": "%PROTOCOL%"
                      #     "duration": "%DURATION%"
                      #     "my_custom_header": "%REQ(MY_CUSTOM_HEADER)%"

  clusters:
    # clusterの名前
    - name: test_cluster
      # タイムアウト値(デフォルトは5秒)
      connect_timeout: 30s
      # クラスターの解決に使用するサービス検出タイプ
      type: LOGICAL_DNS
      # DNS IP アドレス解決ポリシー(デフォルトはAUTO)
      # V4_ONLY が選択されている場合、DNS リゾルバーは IPv4 ファミリ内のアドレスの検索のみを実行
      dns_lookup_family: V4_ONLY
      load_assignment:
        cluster_name: test_cluster
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      # 接続先のホスト
                      address: clickhouse
                      # 接続先のポート
                      port_value: 9000

コンテナ構築

docker-compose.yaml があるディレクトリで以下を実行する。

docker-compose up -d

アクセス確認

curl localhost:9000

一応届いていることが確認できる。

Port 9000 is for clickhouse-client program
You must use port 8123 for HTTP.
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?