Our service uses 4000 port for the backend and written in Rust.
Also, We use gRPC and use same port with 4000.
But I can not add gRPC port. it says it’s already used for HTTP.
How can I add gRPC port?
That’s expected, you can’t start 2 TCP servers (HTTP & GRPC) listening on the same port.
You need to assign another port to your GRPC server. You will get another url/link to contact this port.
Thank you for your reply.
I have just deployed 2 services and tested gRPC.
As I told you, we use the same port for HTTP and gRPC and I confirmed it works well.
Thank you
I don’t use any command for it.
The magic is our code. our backend is bound on 4000 port for incoming requests.
And it’s working as a hybrid service.
If the request is http then we redirect to http service.
if the request is grpc then we redirect to grpc service.
That’s all
It is not possible in our case to do that because there is a reverse proxy in front of your service, and we need to configure the application protocol per port.
If you configure HTTP, the reverse proxy will terminate http2 request and transform them into an HTTP/1.1 request. So it will not work with GRPC as it is http2 only.
If you configure GRPC as protocol, the reverse proxy will not transform http2 into http1, but it will ensure that the traffic is actually grpc over http2 and will not forward it if it is regular http.
So you have 2 solutions, either
create 2 services so they can both listen on the port 4000, as you do
or make start your grpc server on a different port
You can change the default idle timeout for grpc connection in the advance settings of your service.
If there is no activity in the connection after those timeouts, the reverse proxy is going to force close the connection.
Our services were running for 2 years without any issues in other devops platform.
We just used grpc_read_timeout and grpc_send_timeout 3600s
This is related with Nginx config for grpc.
Can you please check this?
On the most recent versions of ingress-nginx, changing these timeouts requires using the nginx.ingress.kubernetes.io/server-snippet annotation. There are plans for future releases to allow using the Kubernetes annotations to define each timeout separately.
If you do that, you will not get any reverse proxy in front of your application, just plain/raw TCP directly exposed to internet.
Beware, that it will create a Load balancer on your cloud provider which cost money, so you should avoid using this setup for doing ephemeral environment,