grpc / grpc-web

gRPC for Web Clients

Home Page:https://grpc.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gRPC Hello World Guide is out of date for Windows and Mac users

itsalexyue opened this issue · comments

The README.md doc for the Hello World guide is out of date for Windows and Mac users. Specifically, the envoy.yaml file should be updated with a clarification for Mac and Windows users that instead of using address: localhost, they should use address: host.docker.internal under the clusters field due to idiosyncrasies with how the docker VM is configured on these machines.

Furthermore, the command to launch the Envoy proxy under these OSes is slightly different (--network=host should be removed) so the command should be:

$ docker run -d -p 8080:8080 helloworld/envoy

Thank you so much. I was unable to get this started after your suggestion initially because I didn't kill all the docker processes/container after changes.

I need another suggestion.
Windows 10 Corp, Envoy in docker container with envoy.yaml config from example page.
Simple copy-paste from helloworld example, did your trick with host.docker.internal under the clusters field.
Still getting error "{code: 14, message: "Http response at 400 or 500 level"}" in browser.
What I'm doing wrong?

Did you build docker container and run it properly? Caveats in the hello world tutorial - it's quite outdated in the docker part - use docker run -d -p 8080:8080 helloworld/envoy as --network=host flag is no longer supported.

I build docker container from PowerShell with command docker build .

My Dockerfile:

FROM envoyproxy/envoy:latest
COPY envoy.yaml /etc/envoy/envoy.yaml
CMD /usr/local/bin/envoy -c /etc/envoy/envoy.yaml

envoy.yaml:

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { 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: echo_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
                enabled: true
          http_filters:
          - name: envoy.grpc_web
          - name: envoy.cors
          - name: envoy.router
  clusters:
  - name: echo_service
    connect_timeout: 0.25s
    type: logical_dns
    http2_protocol_options: {}
    lb_policy: round_robin
    hosts: [{ socket_address: { address: host.docker.internal, port_value: 9090 }}]

I run docker with command:

docker run -d -p 8080:8080 envoyproxy/envoy:latest

Result:
{code: 14, message: "Http response at 400 or 500 level"}

I have added all the changes recommended to get the hello world example to run into this repo https://github.com/oinke/gprc-hello

The terminal still shows:
server_1 | E0302 08:41:34.225022613 7 http_server_filter.cc:271] GET request without QUERY
and when i browse localhost:8080 i can see
upstream connect error or disconnect/reset before headers. reset reason: remote reset

Running on macOS Mojave 10.14.2 with Docker version 18.09.2, build 6247962

Notes added to doc.

@stanley-cheung shall we open this again? the envoy.yaml file is using a property (hosts) that is deprecated https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/cds.proto#envoy-api-file-envoy-api-v2-cds-proto

@gsantopaolo yes it should be opened. It is not still working on the latest Mac.

is this command still working? windows docker

docker run -d -v "$(pwd)"/envoy.yaml:/etc/envoy/envoy.yaml:ro
-p 8080:8080 -p 9901:9901 envoyproxy/envoy:v1.17.0

i tried as well

docker run -d -v ./envoy.yaml:/etc/envoy/envoy.yaml:ro
-p 8080:8080 -p 9901:9901 envoyproxy/envoy:v1.17.0

First command doesnt execute
Second command the following error
status: Downloaded newer image for envoyproxy/envoy:v1.17.0
docker: Error response from daemon: source /var/lib/docker/overlay2/f28fb10fe83102e1a6e097b758bce7854f5047ebc20489805e9ea11b52c0c257/merged/etc/envoy/envoy.yaml is not directory

For reference i'm using Windows 10 Pro but do all my development stuff using WSL2

So if you're using docker-compose to run envoy and you have a grpc service, this is what I had to do

// docker-compose
version: '3.4'

services:

  envoy:
    image: envoyproxy/envoy-dev
    ports:
      - 9901:9901
      - 8080:8080
    volumes:
      - ./envoy_tests/envoy-grpc.yaml:/etc/envoy/envoy.yaml

  chat_service:
    build:
      context: ./microservices
      dockerfile: chat.Dockerfile
    ports:
      - 50051:50051

  gateway_service:
    build:
      context: ./microservices
      dockerfile: gateway.Dockerfile
    ports:
      - 50050:50050

make sure you also update your connection

	connection, err := grpc.Dial("chat_service:50051", grpc.WithInsecure());

this can stay the same for both gateway_service and chat_service

	listen, err := net.Listen("tcp", "0.0.0.0:50050");

your cluster as follows

  clusters:
  - name: gateway_service
    connect_timeout: 0.25s
    type: logical_dns
    http2_protocol_options: {}
    lb_policy: round_robin
    # win/mac hosts: Use address: host.docker.internal instead of address: localhost in the line below
    load_assignment:
      cluster_name: cluster_0
      endpoints:
        - lb_endpoints:
            - endpoint:
                address:
                  socket_address:
                    address: gateway_service
                    port_value: 50050

you'll notice the only difference is i'm using address: gateway_service instead of host.docker.internal or 0.0.0.0 . I'm pretty sure localhost, host.docker.internal, and 0.0.0.0 will work if you're launching all your service under docker-compose because docker-compose will create a new network for you.

To ensure that your connection is working, navigate to http://localhost:9901/clusters

and ensure that your service is not failing to receive connections

gateway_service::192.168.16.3:50050::cx_active::2
gateway_service::192.168.16.3:50050::cx_connect_fail::0
gateway_service::192.168.16.3:50050::cx_total::2

I'm more than happy to update the readme with some new examples. cheers

Hey guys, I've been stuck on this for the longest. I'm currently using

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { 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.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                codec_type: auto
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          route:
                            cluster: greeter_service
                            max_stream_duration:
                              grpc_timeout_header_max: 0s
                      cors:
                        allow_origin_string_match:
                          - prefix: "*"
                        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
                http_filters:
                  - name: envoy.filters.http.grpc_web
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.grpc_web.v3.GrpcWeb
                  - name: envoy.filters.http.cors
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
    - name: greeter_service
      connect_timeout: 0.25s
      type: logical_dns
      # HTTP/2 support
      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: {}
      lb_policy: round_robin
      load_assignment:
        cluster_name: greeter_service
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: host.docker.internal
                      port_value: 9090

as my envoy.yaml

I run docker run -d -v "$(pwd)"/envoy.yaml:/etc/envoy/envoy.yaml:ro -p 8080:8080 -p 9901:9901 envoyproxy/envoy:dev-fd1058b9bd6a512118ef88e6c09eea9a3555696f

but i keep getting this error:

upstream connect error or disconnect/reset before headers. reset reason: remote connection failure, transport failure reason: immediate connect error: Network is unreachable|remote address:[fdc4:f303:9324::254]:9090

I also verified that my grpc server was running by making a js client make a request directly to it

@popoolasubomi Hi! Sorry to hear that you get stuck!

Could you specify the environment you're trying to run on?

And could you try the echo demo per the instructions here and see if they work for you (as a sanity check)?

This thread is very old.

If your issue persist, could you please re-open a new discussion here?
https://github.com/grpc/grpc-web/discussions/categories/q-a-errors-debugging-help

Appreciate it. Thanks!

commented

Getting the same error as @popoolasubomi

I am using latest MacBook pro

ERROR : "503 Service Unavailable" from the API response.

@bot85831 Hi, thanks for the report.

Could you try running the echo demo per the instructions here to see if it works?

https://github.com/grpc/grpc-web?tab=readme-ov-file#advanced-demo-browser-echo-app

It might help rule out some other configuration issues.

upstream connect error or disconnect/reset before headers. reset reason: connection failure, transport failure reason: immediate connect error: Network is unreachable