1
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?

More than 5 years have passed since last update.

gRPC-WebをKotlinバックエンドで試した時のメモ - 3. ReverseProxy編

Last updated at Posted at 2019-09-10

About

このテーマの連載、ReverseProxy編です。

構成

おさらいになりますが、ReverseProxyは、gRPC-Webから受け取ったリクエスト(HTTP/1.1)を、バックエンドのgRPCサービスにリクエストを変換(gRPC,HTTP/2)して転送する役割を担います。

architecture.png

設定

ReverseProxyの設定は、サンプルのreverse-proxyディレクトリに入っていますが、設定ファイルとDockerfileだけです。

Envoyの設定(reverse-proxy.yaml)

Envoyの公式ブログに解説があるので、その設定ファイルを参考にしてすぐに設定できました。

デバッグのために、アクセスログを標準出力に書き出す設定を追加しています。

reverse-proxy/reverse-proxy.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: 8080 }
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        config:
          codec_type: auto
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route:
                  cluster: service
                  max_grpc_timeout: 0s
              cors:
                allow_origin:
                - "*"
                allow_methods: GET, PUT, DELETE, POST, OPTIONS
                allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
                max_age: "1728000"
                expose_headers: custom-header-1,grpc-status,grpc-message
          access_log:
            - name: envoy.file_access_log
              config:
                path: /dev/stdout
          http_filters:
          - name: envoy.grpc_web
          - name: envoy.cors
          - name: envoy.router
  clusters:
  - name: service
    connect_timeout: 0.25s
    type: logical_dns
    http2_protocol_options: {}
    lb_policy: round_robin
    hosts:
    - socket_address:
        address: service
        port_value: 6565

Dockerfile

コンテナ化します。

FROM envoyproxy/envoy-alpine

EXPOSE 8080
EXPOSE 9901

ADD reverse-proxy.yaml /etc/reverse-proxy.yaml

ENTRYPOINT [ "/usr/local/bin/envoy", "-c", "/etc/reverse-proxy.yaml", "--service-cluster reverse-proxy" ]

次回

次回はWebフロントエンド編です。

1
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
1
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?