googleforgames / agones

Dedicated Game Server Hosting and Scaling for Multiplayer Games on Kubernetes
https://agones.dev
Apache License 2.0
6.09k stars 812 forks source link

Question: How to get gameserver port in pod? #1258

Closed xinyu7git closed 4 years ago

xinyu7git commented 4 years ago
[root@172-18-212-12 ~]# kubectl get gameservers
NAME                     STATE   ADDRESS          PORT   NODE             AGE
simple-udp-8wr2k-2fqzm   Ready   172.18.178.251   7126   172-18-178-251   10m
simple-udp-8wr2k-4ghbp   Ready   172.18.178.251   7289   172-18-178-251   8m57s
simple-udp-8wr2k-4vxnf   Ready   172.18.178.251   7387   172-18-178-251   10m
simple-udp-8wr2k-gf9s6   Ready   172.18.178.251   7716   172-18-178-251   8m57s
simple-udp-8wr2k-hcs4s   Ready   172.18.178.251   7672   172-18-178-251   8m57s
simple-udp1-qkh55        Ready   172.18.178.251   7171   172-18-178-251   25m

I want to get gameservers port in a pod, like get "7126" in pod "simple-udp-8wr2k-2fqzm" , i can't find a way in docs, anyone konws?

xinyu7git commented 4 years ago

/kind/question

xinyu7git commented 4 years ago

not in env:

/ $ env
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_SERVICE_PORT=443
HOSTNAME=simple-udp-8wr2k-2fqzm
SHLVL=1
HOME=/home/server
AGONES_SDK_GRPC_PORT=9357
TERM=xterm
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
AGONES_SDK_HTTP_PORT=9358
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_SERVICE_HOST=10.96.0.1
PWD=/
roberthbailey commented 4 years ago

/kind question

roberthbailey commented 4 years ago

/label question

roberthbailey commented 4 years ago

Are you using the game server SDK in your pod? You should be able to call the GameServer() function (see https://agones.dev/site/docs/guides/client-sdks/#gameserver) to get all of the information that you can see from kubectl get gameserver simple-udp-8wr2k-2fqzm within that pod.

xinyu7git commented 4 years ago

Ok, i got the port by GameServer() Function in client-sdk , thanks!

[root@172-18-178-251 ~]# docker logs f293b4a35a43
+ /root/main
2020/01/07 15:50:21 Starting TCP server, listening on port 7654
2020/01/07 15:50:21 Creating SDK instance
2020/01/07 15:50:21 Starting Health Ping
2020/01/07 15:50:21 Marking this server as ready
gs= object_meta:<name:"gs-example-skh22" namespace:"default" 
uid:"d2bb89d3-40b3-422c-89f9-623cfad56d70" resource_version:"250550" 
generation:4 creation_timestamp:1578383417 annotations:<key:"agones.dev/sdk-version" value:"1.2.0" > > 
spec:<health:<period_seconds:5 failure_threshold:3 initial_delay_seconds:5 > > 
status:<state:"Scheduled" address:"172.18.178.251" ports:<name:"default" port:7167 > >  err= <nil>
roberthbailey commented 4 years ago

Sounds like your problem is resolved so I'm going to mark this as closed.

/close