1

I am trying to access gRPC service using REST. I have setup an envoy server; but neither I am able to access envoy admin console nor able to access gRPC service from REST. Please find below envoy-config.yml file.

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }         #1

static_resources:
  listeners:
    - name: main-listener
      address:
        socket_address: { address: 0.0.0.0, port_value: 51051 }      #2
      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: grpc_json
                codec_type: AUTO
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains: [ "*" ]
                      routes:
                        - match: { prefix: "/" , grpc: { } }  # 3a grpc:{} means that requests are only forwarded if they are found in the grpc service definition, returning 404 for others
                          route: { cluster: grpc-backend-services, timeout: { seconds: 60 } }   #3b
                http_filters:
                  - name: envoy.grpc_json_transcoder
                    # configuration docs: https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/http/transcoder/v2/transcoder.proto
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
                      proto_descriptor: "/data/reservation_service_definition.pb"             #4
                      services: [ "reservations.v1.ReservationService" ]                        #5
                      print_options:
                        add_whitespace: true
                        always_print_primitive_fields: true
                        always_print_enums_as_ints: false
                        preserve_proto_field_names: false                                     #6
                  - name: envoy.filters.http.router
                    typed_config:
                        "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
    - name: grpc-backend-services
      type: LOGICAL_DNS
      lb_policy: ROUND_ROBIN
      dns_lookup_family: V4_ONLY
      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: grpc
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      # WARNING: "docker.for.mac.localhost" has been deprecated from Docker v18.03.0.
                      # If you're running an older version of Docker, please use "docker.for.mac.localhost" instead.
                      # Reference: https://docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-18030-ce-mac59-2018-03-26
                      address: host.docker.internal
                      port_value: 9091

The gRPC service is running on port 9091.

envoy container is running

pushpak.mittal@BLRJPT121327LT grpc-server % docker ps
CONTAINER ID   IMAGE                                                           COMMAND                  CREATED          STATUS          PORTS     NAMES
5a2ec1db0b54   envoyproxy/envoy:dev-6c702f45fadf4abd2f24605e3d9e81c748b13f85   "/docker-entrypoint.…"   42 minutes ago   Up 42 minutes             envoy
pushpak.mittal@BLRJPT121327LT grpc-server % 

My POST request

 curl -X POST \
   http://localhost:51051/v1/reservations \
   -H 'Content-Type: application/json' \
   -d '{
     "title": "Lunchmeeting2",
     "venue": "JDriven Coltbaan 3",
     "room": "atrium",
     "timestamp": "2018-10-10T11:12:13",
     "attendees": [
         {
             "ssn": "1234567890",
             "firstName": "Jimmy",
             "lastName": "Jones"
         },
         {
             "ssn": "9999999999",
             "firstName": "Dennis",
             "lastName": "Richie"
         }
     ]
 }'

Response

curl: (7) Failed to connect to localhost port 51051 after 8 ms: Connection refused
pushpak.mittal@BLRJPT121327LT grpc-server % 

Docker run command

docker run -it --rm --name envoy --network="host"\
             -v "$(pwd)/reservation_service_definition.pb:/data/reservation_service_definition.pb:ro" \
             -v "$(pwd)/envoy-config.yml:/etc/envoy/envoy.yaml:ro" \
             envoyproxy/envoy:dev-6c702f45fadf4abd2f24605e3d9e81c748b13f85
Pushpak
  • 147
  • 8

0 Answers0