Skip to main content
A GameServerAllocation is used to allocate a GameServer from a Fleet, GameServerSet, or any set of GameServers that match specified selectors. The allocation process finds a suitable GameServer, marks it as Allocated, and returns its connection information.

API Version

allocation.agones.dev/v1

Kind

GameServerAllocation

Resource Structure

apiVersion: allocation.agones.dev/v1
kind: GameServerAllocation
metadata:
  name: allocation-example
spec:
  selectors:
    - matchLabels:
        agones.dev/fleet: green-fleet
    - matchLabels:
        agones.dev/fleet: blue-fleet
  scheduling: Packed
  metadata:
    labels:
      mode: deathmatch
    annotations:
      map: garden22

Spec Fields

The spec field defines the allocation criteria and actions.

selectors

spec.selectors
array
Ordered list of GameServer label selectors. If the first selector finds no match, the allocation attempts the second selector, and so on. This is useful for fallback scenarios like canary testing.Note: Either use selectors or the deprecated required/preferred fields, not both.

required (Deprecated)

spec.required
object
Deprecated: Use selectors instead.GameServer selector from which to choose GameServers. If selectors is set, this field is ignored.

preferred (Deprecated)

spec.preferred
array
Deprecated: Use selectors instead.Ordered list of preferred GameServer selectors. If selectors is set, this field is ignored.

scheduling

spec.scheduling
string
default:"Packed"
Defines how GameServers are organized for selection:
  • Packed - Aimed at dynamic clusters (cloud), bin packs onto nodes for efficient resource usage
  • Distributed - Aimed at static clusters, distributes across nodes for fault tolerance

priorities

spec.priorities
array
Beta Feature (CountsAndLists flag)Alters the order in which GameServers are searched. Priority sorting is in descending importance (position 0 checked first).
  • For Packed: Priority list is the tie-breaker within least-utilized infrastructure
  • For Distributed: Entire selection is sorted by this priority list

metadata

spec.metadata
object
Custom metadata added to the GameServer at allocation time. Useful for passing session-specific data.

counters

spec.counters
map[string]CounterAction
Beta Feature (CountsAndLists flag)Counter actions to perform during allocation.

lists

spec.lists
map[string]ListAction
Beta Feature (CountsAndLists flag)List actions to perform during allocation.

multiClusterSetting

spec.multiClusterSetting
object
Configuration for multi-cluster allocation. If specified, allocation can span multiple clusters.

Status Fields

The status field contains the allocation result.

state

status.state
string
Allocation state. Possible values:
  • Allocated - Allocation successful
  • UnAllocated - No suitable GameServer found
  • Contention - Allocation failed due to race condition/contention

gameServerName

status.gameServerName
string
Name of the allocated GameServer. Empty if allocation failed.

ports

status.ports
array
Array of ports exposed by the allocated GameServer.

address

status.address
string
Primary IP address or hostname to connect to the GameServer.

addresses

status.addresses
array
All available addresses for the GameServer (internal IP, external IP, hostname).

nodeName

status.nodeName
string
Kubernetes node hosting the allocated GameServer.

source

status.source
string
Source of the allocation:
  • local - Allocated from local cluster
  • <endpoint> - Allocated from remote cluster (endpoint of remote agones-allocator)

metadata

status.metadata
object
Metadata from the allocated GameServer at allocation time.

counters

status.counters
map[string]CounterStatus
Beta Feature (CountsAndLists flag)Counter values from the allocated GameServer after allocation actions.

lists

status.lists
map[string]ListStatus
Beta Feature (CountsAndLists flag)List values from the allocated GameServer after allocation actions.

Allocation Process

The allocation process follows these steps:
  1. Selector Evaluation: Iterate through selectors in order until a match is found
  2. Filtering: Apply all selector criteria (labels, state, counters, lists, players)
  3. Sorting: Sort matching GameServers by:
    • Scheduling strategy (Packed or Distributed)
    • Priorities (if specified)
    • Default tie-breakers
  4. Selection: Choose the first GameServer from sorted list
  5. State Update: Atomically update GameServer to Allocated state
  6. Metadata Application: Apply labels/annotations from spec.metadata
  7. Counter/List Actions: Perform counter/list operations
  8. Response: Return GameServer connection details in status

Contention Handling

If multiple allocations target the same GameServer simultaneously:
  • Only one succeeds (winner of the race condition)
  • Others receive state: Contention
  • Client should retry the allocation

Selector Fallback

With multiple selectors:
selectors:
  - matchLabels:
      version: v2  # Try v2 first (canary)
  - matchLabels:
      version: v1  # Fall back to v1 (stable)
Allocation attempts v2, falls back to v1 if no v2 GameServers available.

Use Cases

Basic Fleet Allocation

Allocate any Ready GameServer from a Fleet:
selectors:
  - matchLabels:
      agones.dev/fleet: main-fleet

Canary Deployments

Try new version first, fall back to stable:
selectors:
  - matchLabels:
      version: canary
  - matchLabels:
      version: stable

Session Management

Allocate GameServer with room for specific player count:
selectors:
  - matchLabels:
      game: shooter
    counters:
      players:
        minAvailable: 4  # Need room for 4 players
counters:
  players:
    action: Increment
    amount: 4  # Reserve 4 slots

Re-connection

Find already allocated GameServer for reconnection:
selectors:
  - matchLabels:
      session-id: abc123
    gameServerState: Allocated

Geographic Distribution

Allocate from preferred region with fallback:
selectors:
  - matchLabels:
      region: us-west
  - matchLabels:
      region: us-east
  - matchLabels:
      region: eu-central

Notes

GameServerAllocation is a create-only resource. Each allocation creates a new GameServerAllocation object in the cluster that persists as a record of the allocation.
Counter and list actions are performed after allocation succeeds. If actions fail, the GameServer remains allocated but actions may not be applied.
The allocation process is atomic at the GameServer state transition level. However, metadata updates and counter/list actions happen in separate operations.
When using gameServerState: Allocated for re-connection scenarios, ensure proper label/annotation selectors to avoid allocating wrong sessions.
Multi-cluster allocation requires additional setup with agones-allocator service and AllocationEndpoint/GameServerAllocationPolicy resources. See multi-cluster documentation for details.

Build docs developers (and LLMs) love