googleforgames / agones

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

Fleet Autoscaler is shutting down reserved servers #2209

Closed D3m1urg3 closed 3 years ago

D3m1urg3 commented 3 years ago

What happened: Our gameservers require registering into our backend. Therefore, we are implementing the corresponding gs lifecycle logic as descibed in agones documentation.

The gameserver state in agones when the server starts follows:

  1. Scheduled
  2. Reserved until register
  3. Ready waiting for a game session.

Here is the fleetautoscaler.yaml used:

apiVersion: "autoscaling.agones.dev/v1"
kind: FleetAutoscaler
metadata:
  name: my-autofleet
spec:
  # The name of the fleet to attach to and control. Must be an existing Fleet in the same namespace
  # as this FleetAutoscaler
  fleetName: my-fleet
  # The autoscaling policy
  policy:
    type: Buffer
    # parameters of the buffer policy
    buffer:
      # Size of a buffer of "ready" and "reserved" game server instances.
      # The FleetAutoscaler will scale the fleet up and down trying to maintain this buffer, 
      # as instances are being allocated or terminated.
      # Note that "reserved" game servers could not be scaled down.
      # It can be specified either in absolute (i.e. 5) or percentage format (i.e. 5%)
      bufferSize: 1
      # minimum fleet size to be set by this FleetAutoscaler. 
      # if not specified, the actual minimum fleet size will be bufferSize
      # minReplicas: 10
      # maximum fleet size that can be set by this FleetAutoscaler
      # required
      maxReplicas: 4

and here is the fleet.yaml:

apiVersion: "agones.dev/v1"
kind: Fleet
metadata:
  # generate a unique name
  # will need to be created with `kubectl create`
  name: ed-fleet
spec:
  replicas: 1
  template:
    spec:
      ports:
        - name: game
          portPolicy: Dynamic
          containerPort: 7777
          protocol: UDP
      template:
        spec:
          containers:
            - name: ed-server
              image: my-repo/my-dedicated:agones_20210802_1508
              #imagePullPolicy: Always # add for development
              volumeMounts:
              - mountPath: "/mnt/azure"
                name: volume
              resources:
                requests:
                  cpu: "800m"
          imagePullSecrets:
          - name: myreg
          volumes:
            - name: volume
              persistentVolumeClaim:
                claimName: my-azurefile

Regardless of what the comment says the autoscaler Shutdowns the Reserved server and starts a new one who then proceeds to shutdown in a never ending cycle.

What you expected to happen: The autoscaller does not touch a reserved gs.

How to reproduce it (as minimally and precisely as possible): Launch a gameserver with the registering logic implemented and watch the autoscaller shutdown the reserved servers.

Anything else we need to know?: The gameserver launch by itself work fine completing the logic correctly.

Environment:

markmandel commented 3 years ago

So autoscalers only change Fleet sizes - they don't touch what is shutdown or not.

If you take a Fleet, reserve a few GameServers and then scale it down to 0 - do those Reserved instances stay, or do they get removed?

D3m1urg3 commented 3 years ago

Indeed the problem seems to be on our end. Thanks for the help.

markmandel commented 3 years ago

No worries, just glad you got it sorted!