×
Community Blog [Agones Series – Part 3] The Scale In and Scale Out of the Game Server

[Agones Series – Part 3] The Scale In and Scale Out of the Game Server

Part 3 of the Agones Series describes how to scale the game server in and out in Agones.

By Qiuyang Liu (Liming)

1

We deployed a game server object in The First Bite of Agones and created a game server on ACK. This article will introduce the scale in and out of the game server, the core capability of Agones.

Fleet

There are many management objects on top of the most basic Pod objects in Kubernetes, such as Deployment and StatefulSet. In Agones, in addition to the previously mentioned GameServer object, there is a similar management object, Fleet. Those who are familiar with Deployment can understand Fleet easily. The object that Fleet manages is called GameServerSet, which is similar to ReplicaSet and Fleet-GameServerSet-GameServer multi-level management to implement the rolling upgrade. You can specify the number of replicas in the fleet object to expand and scale in gs. Let's look at the scaling process of Agones through experiments.

First, create a Fleet in the Kubernetes cluster with Agones installed:

apiVersion: "agones.dev/v1"
kind: Fleet
metadata:
  name: simple-game-server
spec:
  replicas: 2
  template:
    spec:
      ports:
      - name: default
        containerPort: 7654
      template:
        spec:
          containers:
          - name: simple-game-server
            image: gcr.io/agones-images/simple-game-server:0.12
            resources:
              requests:
                memory: "64Mi"
                cpu: "20m"
              limits:
                memory: "64Mi"
                cpu: "20m"

The following objects are added to the cluster:

kubectl get fleet 
NAME                 SCHEDULING   DESIRED   CURRENT   ALLOCATED   READY   AGE
simple-game-server   Packed       2         2         0           2       17s

kubectl get gss
NAME                       SCHEDULING   DESIRED   CURRENT   ALLOCATED   READY   AGE
simple-game-server-rhjtz   Packed       2         2         0           2       20s

kubectl get gs
NAME                             STATE   ADDRESS           PORT   NODE                     AGE
simple-game-server-rhjtz-gnhnx   Ready   xxx.xxx.xxx.xxx   7012   cn-xxx.xxx.xxx.xxx.xxx   21s
simple-game-server-rhjtz-zhxts   Ready   xxx.xxx.xxx.xxx   7909   cn-xxx.xxx.xxx.xxx.xxx   21s

kubectl get po
NAME                             READY   STATUS    RESTARTS   AGE
simple-game-server-rhjtz-gnhnx   2/2     Running   0          24s
simple-game-server-rhjtz-zhxts   2/2     Running   0          24s

Both gs can be accessed at this time.

Manual Scale In and Out

Let's try the scale out:

kubectl scale fleet simple-game-server --replicas=5
fleet.agones.dev/simple-game-server scaled

You can see Fleet's events, control the GameServerSet, and expand its number of replicas from 2 to 5:

kubectl describe fleet simple-game-server
...
Events:
  Type    Reason                 Age    From              Message
  ----    ------                 ----   ----              -------
  Normal  CreatingGameServerSet  4m37s  fleet-controller  Created GameServerSet simple-game-server-rhjtz
  Normal  ScalingGameServerSet   2m4s   fleet-controller  Scaling active GameServerSet simple-game-server-rhjtz from 2 to 5

The object status of the current cluster:

kubectl get fleet
NAME                 SCHEDULING   DESIRED   CURRENT   ALLOCATED   READY   AGE
simple-game-server   Packed       5         5         0           5       2m43s

kubectl get gss
NAME                       SCHEDULING   DESIRED   CURRENT   ALLOCATED   READY   AGE
simple-game-server-rhjtz   Packed       5         5         0           5       2m46s

kubectl get gs
NAME                             STATE   ADDRESS           PORT   NODE                     AGE
simple-game-server-rhjtz-g72pq   Ready   xxx.xxx.xxx.xxx   7483   cn-xxx.xxx.xxx.xxx.xxx   14s
simple-game-server-rhjtz-gnhnx   Ready   xxx.xxx.xxx.xxx   7012   cn-xxx.xxx.xxx.xxx.xxx   2m47s
simple-game-server-rhjtz-jqpxt   Ready   xxx.xxx.xxx.xxx   7768   cn-xxx.xxx.xxx.xxx.xxx   14s
simple-game-server-rhjtz-pstgv   Ready   xxx.xxx.xxx.xxx   7486   cn-xxx.xxx.xxx.xxx.xxx   14s
simple-game-server-rhjtz-zhxts   Ready   xxx.xxx.xxx.xxx   7909   cn-xxx.xxx.xxx.xxx.xxx   2m47s

kubectl get po
NAME                             READY   STATUS    RESTARTS   AGE
simple-game-server-rhjtz-g72pq   2/2     Running   0          16s
simple-game-server-rhjtz-gnhnx   2/2     Running   0          2m49s
simple-game-server-rhjtz-jqpxt   2/2     Running   0          16s
simple-game-server-rhjtz-pstgv   2/2     Running   0          16s
simple-game-server-rhjtz-zhxts   2/2     Running   0          2m49s

Automatic Scale In and Out

In Kubernetes, Horizontal Pod Autoscaler (HPA) is used to adjust the number of pods automatically. Agones uses FleetAutoscaler to adjust the number of gs automatically. The following is a simple example:

apiVersion: "autoscaling.agones.dev/v1"
kind: FleetAutoscaler
metadata:
  name: simple-game-server-autoscaler
spec:
  fleetName: simple-game-server
  policy:
    type: Buffer
    buffer:
      bufferSize: 2
      minReplicas: 0
      maxReplicas: 10

Here, FleetName is used to specify the Fleet object that automatically scales the binding. The automatic scaling type is a buffer whose size is 2, and the maximum number of replicas is set to 10. The buffer size here is the number relative to the Allocated state gs. We know the normally created gs will be in the Ready state. Agones has designed an Allocated state to adapt to the open match mechanism, which represents allocation and use. The gs in this state means the game server can be connected by the player to play the game. If the buffer size is 2, the number of replicas in gs is 2 more than that in Allocated gs. The meaning of buffer is that fleet can be automatically expanded when the number of players increases, thereby reducing the startup time of the game server. Let's use the FleetAutoscaler with gameserverallocation.

First, create a gameserverallocation:

apiVersion: "allocation.agones.dev/v1"
kind: GameServerAllocation
spec:
  required:
    matchLabels:
      agones.dev/fleet: simple-game-server

Here, matchLabels is used to match the corresponding fleet.

The status of all gs is listed below, and the status of one gs becomes Allocated:

kubectl get gs
NAME                             STATE       ADDRESS           PORT   NODE                     AGE
simple-game-server-rhjtz-g72pq   Ready       xxx.xxx.xxx.xxx   7483   cn-xxx.xxx.xxx.xxx.xxx   145m
simple-game-server-rhjtz-gnhnx   Ready       xxx.xxx.xxx.xxx   7012   cn-xxx.xxx.xxx.xxx.xxx   147m
simple-game-server-rhjtz-jqpxt   Ready       xxx.xxx.xxx.xxx   7768   cn-xxx.xxx.xxx.xxx.xxx   145m
simple-game-server-rhjtz-pstgv   Ready       xxx.xxx.xxx.xxx   7486   cn-xxx.xxx.xxx.xxx.xxx   145m
simple-game-server-rhjtz-zhxts   Allocated   xxx.xxx.xxx.xxx   7909   cn-xxx.xxx.xxx.xxx.xxx   147m

We will scale in and adjust the number of gs to 0:

kubectl get gs
NAME                             STATE       ADDRESS           PORT   NODE                     AGE
simple-game-server-rhjtz-zhxts   Allocated   xxx.xxx.xxx.xxx   7909   cn-xxx.xxx.xxx.xxx.xxx   147m

Although the number of replicas is 0, the gs in the Allocated state will not be deleted since the game may be in progress.

Let's create a FleetAutoscaler and set the buffer size to 2 to see the changes in gs:

kubectl apply -f fleetautoscaler.yaml 
fleetautoscaler.autoscaling.agones.dev/simple-game-server-autoscaler created

kubectl get gs
NAME                             STATE       ADDRESS           PORT   NODE                     AGE
simple-game-server-rhjtz-4dnrk   Ready       xxx.xxx.xxx.xxx   7734   cn-xxx.xxx.xxx.xxx.xxx   12s
simple-game-server-rhjtz-rsnnm   Ready       xxx.xxx.xxx.xxx   7067   cn-xxx.xxx.xxx.xxx.xxx   12s
simple-game-server-rhjtz-zhxts   Allocated   xxx.xxx.xxx.xxx   7909   cn-xxx.xxx.xxx.xxx.xxx   155m

It automatically expands to 3 gs, and the total number is 1 more than the number of Allocated.

We manually allocate another gs to Allocated:

kubectl create -f gameserverallocation.yaml

kubectl get gs
NAME                             STATE       ADDRESS           PORT   NODE                     AGE
simple-game-server-rhjtz-4dnrk   Allocated   xxx.xxx.xxx.xxx   7734   cn-xxx.xxx.xxx.xxx.xxx   3m36s
simple-game-server-rhjtz-rsnnm   Ready       xxx.xxx.xxx.xxx   7067   cn-xxx.xxx.xxx.xxx.xxx   3m36s
simple-game-server-rhjtz-tgxwj   Ready       xxx.xxx.xxx.xxx   7030   cn-xxx.xxx.xxx.xxx.xxx   6s
simple-game-server-rhjtz-zhxts   Allocated   xxx.xxx.xxx.xxx   7909   cn-xxx.xxx.xxx.xxx.xxx   159m

The total number gs has been expanded to 4.

0 0 0
Share on

You may also like

Comments

Related Products