Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding AGONES_SDK_GRPC_HOST to NewSDK #1183

Closed
castaneai opened this issue Nov 13, 2019 · 21 comments
Closed

Adding AGONES_SDK_GRPC_HOST to NewSDK #1183

castaneai opened this issue Nov 13, 2019 · 21 comments
Labels
kind/documentation Documentation for Agones kind/feature New features for Agones
Milestone

Comments

@castaneai
Copy link
Collaborator

In local development, I'd like to run Agones SDK server on docker-compose.
However, the current Agones SDK always connect to localhost.

GameServer and Local SDK server cannot be run on different containers.

agones/sdks/go/sdk.go

Lines 45 to 49 in 1071930

p := os.Getenv("AGONES_SDK_GRPC_PORT")
if p == "" {
p = "59357"
}
addr := fmt.Sprintf("localhost:%s", p)

One solution is to add AGONES_SDK_GRPC_HOST that can override localhost. What do you think?

@castaneai castaneai added the kind/feature New features for Agones label Nov 13, 2019
@roberthbailey
Copy link
Member

Out of curiosity, what value would you put in for the server address running on docker compose? I'm assuming compose doesn't had a concept of pods to put the two containers into the same network namespace, which is why you would need to override the address.

@castaneai
Copy link
Collaborator Author

For example, in the following docker-compose.yml I will set AGONES_SDK_GRPC_HOST=agones-sdk-server.
(docker-compose provides DNS resolution with the same name as the service name.)

version: "3"
services:
  gameserver:
    ...
  agones-sdk-server:
    ...

@markmandel
Copy link
Member

Could you do host networking for all your containers in compose?

(Not saying that's a great idea, but it's a workaround for now)

@roberthbailey
Copy link
Member

Can you steer containers in compose to land on the same underlying node? If not, host networking wouldn't help.

@markmandel
Copy link
Member

Docker compose is single node isn't it? (I haven't used it for a while) - so essentially local development only?

@roberthbailey
Copy link
Member

Good question. I've never used it, but based on https://docs.docker.com/compose/production/ it looks like you can run across multiple nodes using docker swarm:

If you want to scale up your application, you can run Compose apps on a Swarm cluster.

@markmandel
Copy link
Member

@castaneai I assume you are using this for just local development?

It sounds like you are trying to replicate a Pod system locally for development?

@castaneai
Copy link
Collaborator Author

Yes, I'm using docker-compose for local development (on single node).
I have no intention to run on Swarm.
The reason I want to separate services in this way is because Docker recommends running only one process on one container.

@roberthbailey
Copy link
Member

In that case, does @markmandel's suggestion above about using host network unblock you?

@castaneai
Copy link
Collaborator Author

That's true for Linux. However, host network is not supported on Mac and Windows. 😢

https://docs.docker.com/network/host/

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

@markmandel
Copy link
Member

Can you do a variation on https://blog.mikesir87.io/2019/03/sharing-network-namespaces-in-docker/ , but with compose?

(Basically use another container's network?)

@castaneai
Copy link
Collaborator Author

Adding network_mode: service:gameserver works fine on docker-compose!
Thank you for the advice!

Here is my example repo.

https://github.com/castaneai/agones-sdk-playground

version: "3"
services:
  gameserver:
    build: .
  sdk-server:
    build: ./sdk-server
    network_mode: service:gameserver

@markmandel
Copy link
Member

This sounds like it could be a cool thing to add to our docs somewhere. 👍

@markmandel markmandel added the kind/documentation Documentation for Agones label Nov 20, 2019
@mthssdrbrg
Copy link
Contributor

I currently have a use case where it would be beneficial to be able to set the host / address (for both HTTP and GRPC) for the SDKs so that they can reach a SDK server (custom SDK server that doesn't bind to localhost by default) running in a different pod. I'm currently working around this by adding a TCP proxy sidecar that listens on localhost and forwards any connections to the SDK server, which works, but it would be great if I didn't have to add the sidecar :)

@roberthbailey
Copy link
Member

Can you elaborate more about why you find it useful to run a custom SDK server (and if you can say, how different is it from the canonical implementation)? If you are running a proxy sidecar anyway, I'm curious what the advantage is of running the sdkserver is a separate pod. Is it always on the same machine or can it be elsewhere in the cluster?

It would be straightforward to modify the SDKs to take an environment variable for the host to connect to, but by pointing it outside of the current pod, I wonder if that ends up breaking some of the assumptions that are currently built into the different SDKs (e.g. they don't implement much retry logic since grpc requests to localhost pretty much always succeed once the sdkserver is up and running).

@mthssdrbrg
Copy link
Contributor

Can you elaborate more about why you find it useful to run a custom SDK server (and if you can say, how different is it from the canonical implementation)? If you are running a proxy sidecar anyway, I'm curious what the advantage is of running the sdkserver is a separate pod. Is it always on the same machine or can it be elsewhere in the cluster?

I have some custom readiness logic, otherwise the implementation is the same (it's in go so there isn't really much code as I'm reusing most of the original SDK server).
So the sdkserver is running in the GameServer pod as per usual (but with a different image via the flag available by the Agones controller) alongside the game container and other sidecars, and then I have other pods (for various reasons) that use the Agones client SDKs, and these typically run on different machines (at the mercy of the scheduler).

It would be straightforward to modify the SDKs to take an environment variable for the host to connect to, but by pointing it outside of the current pod, I wonder if that ends up breaking some of the assumptions that are currently built into the different SDKs (e.g. they don't implement much retry logic since grpc requests to localhost pretty much always succeed once the sdkserver is up and running).

Ah, good point! That is definitely a concern, and to be honest not something that I have thought much about this far. Perhaps having a proper proxy with retries and whatnot would be a more reasonable solution than changing the client SDKs.

@markmandel
Copy link
Member

Came up in #2054 - but I'm wondering if a set of open source sidecars that have different types of use cases would be a good way to tackle this, rather than trying to resolve it in core?

@mthssdrbrg
Copy link
Contributor

Came up in #2054 - but I'm wondering if a set of open source sidecars that have different types of use cases would be a good way to tackle this, rather than trying to resolve it in core?

Yeah, I'm not sure it fits in core. I think sidecar(s) makes the most sense at this time, to test different things to see what works and what doesn't for different scenarios.

@dzmitry-lahoda
Copy link
Contributor

i have windows containers, for them options like network_mode: service:gameserver

 Cannot start service agones: sharing of hyperv containers network is not supported

@dzmitry-lahoda
Copy link
Contributor

AGONES_SDK_HOST may be better name

@roberthbailey
Copy link
Member

This issue hasn't been updated since #2677 was merged so I'm going to mark it as fixed by that PR.

If there is anything else to do here, please feel free to re-open it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Documentation for Agones kind/feature New features for Agones
Projects
None yet
Development

No branches or pull requests

6 participants