Allocation Basics
When you create a GameServerAllocation, Agones:- Finds GameServers matching your selectors
- Sorts them by scheduling strategy and priorities
- Transitions the chosen GameServer from Ready → Allocated
- Applies metadata patches (labels, annotations, counters, lists)
- Returns connection details to the client
pkg/apis/allocation/v1/gameserverallocation.go
Allocation Lifecycle
Allocation States (gameserverallocation.go:33-41):
- Allocated: Successfully allocated a GameServer
- UnAllocated: No matching GameServers found
- Contention: Allocation failed due to concurrent update conflict (retry recommended)
Selectors
Selectors define which GameServers are eligible for allocation: Source:gameserverallocation.go:128-156
Label Selectors
Use Kubernetes label matching:In: Value must be in the listNotIn: Value must not be in the listExists: Key must exist (any value)DoesNotExist: Key must not exist
Ordered Selectors
Selectors are evaluated in order. If no match is found, the next selector is tried:This is useful for canary deployments, A/B testing, or gradual rollouts where you want to prefer specific GameServers but have fallbacks.
GameServer State Filter
Specify which state GameServers must be in: Source:gameserverallocation.go:132-135
- Ready (default): Allocate from available GameServers
- Allocated: Re-allocate an already allocated GameServer (for reconnection scenarios)
Player Capacity Filters (Alpha)
Filter by available player slots: Source:gameserverallocation.go:158-162
PlayerAllocationFilter
Counter Filters (Beta)
Filter by Counter values and available capacity: Source:gameserverallocation.go:164-178
capacity - count
Matching logic (gameserverallocation.go:294-318):
- All specified counters must match
maxCount: 0ormaxAvailable: 0means unlimited (max int64)- If Counter doesn’t exist on GameServer, it doesn’t match
CountsAndLists
List Filters (Beta)
Filter by List values and available capacity: Source:gameserverallocation.go:180-192
capacity - len(values)
Matching logic (gameserverallocation.go:364-397):
- All specified lists must match
containsValuechecks if value exists in the listmaxAvailable: 0means unlimited- If List doesn’t exist on GameServer, it doesn’t match
CountsAndLists
Scheduling Strategies
Control how GameServers are selected when multiple matches exist: Source:gameserverallocation.go:108-109
- Packed (Default)
- Distributed
Goal: Minimize infrastructure usageBehavior:
- Groups allocations on fewer nodes
- Allows cluster autoscaler to scale down empty nodes
- Picks GameServer from most utilized node first
Priorities (Beta)
Define custom sorting for GameServer selection: Source:gameserverallocation.go:88-100
- Position 0 has highest priority
- Compares available capacity between GameServers
- Ascending: Prefers GameServers with less available capacity
- Descending: Prefers GameServers with more available capacity
- Packed
- Distributed
Priorities are a tie-breaker within the same node:
- First, choose most utilized node (most GameServers)
- Within that node, use priorities to pick the best GameServer
CountsAndLists
Metadata Patching
Apply labels and annotations to the allocated GameServer: Source:gameserverallocation.go:111-113, gameserverallocation.go:552-564
- Session tracking and identification
- Debugging and observability
- Custom routing or load balancing
- Integration with external systems
Metadata is applied atomically with the allocation. If allocation fails, no metadata changes are made.
Counter and List Actions (Beta)
Modify Counters and Lists during allocation:Counter Actions
Source:gameserverallocation.go:194-205, gameserverallocation.go:320-337
- Increment: Adds
amountto current count (clamped to capacity) - Decrement: Subtracts
amountfrom current count (clamped to 0) - Capacity: Updates maximum capacity
gameserverallocation.go:511-531):
amountmust be positive- If
actionis set,amountmust also be set - Both
actionandcapacitycan be specified together
List Actions
Source:gameserverallocation.go:207-218, gameserverallocation.go:339-362
- addValues: Appends unique values (duplicates ignored)
- deleteValues: Removes specified values (non-existent values ignored)
- capacity: Updates maximum capacity (0-1000)
gameserverallocation.go:533-544):
capacitymust be 0-1000 if specified- Duplicate values in
addValuesare silently ignored - Non-existent values in
deleteValuesare silently ignored
CountsAndLists
Allocation Response
Successful allocation returns connection details: Source:gameserverallocation.go:566-581
Performing Allocations
Via kubectl
Via Allocator Service
For production, use the allocator service (gRPC/REST):- Sub-second allocation latency
- Multi-cluster allocation support
- No need for Kubernetes credentials
- Production-ready authentication
Multi-Cluster Allocation
Allocate across multiple Kubernetes clusters: Source:gameserverallocation.go:72-74
- GameServerAllocationPolicy resources in each cluster
- Allocator service configured with multi-cluster support
- Network connectivity between allocator and target clusters
Multi-cluster allocation enables global GameServer pools, geographic routing, and cross-region failover.
Common Patterns
Session-Based Allocation
Region-Aware Allocation
Reconnection Flow
Retrieve an already-allocated GameServer:Troubleshooting
No GameServers allocated (UnAllocated)
Contention errors
Multiple allocations competing for the same GameServer:Contention is expected under high load. Clients should retry with exponential backoff.
Allocation too slow
Best Practices
Use allocator service in production
The allocator service provides sub-second latency and multi-cluster support.
Implement retry logic
Handle Contention states with exponential backoff and retries.
Add session metadata
Use labels/annotations for tracking, debugging, and analytics.
Monitor allocation rates
Track allocation success rate and latency to right-size Fleets.
Next Steps
Allocator Service Setup
Configure the production allocator service
Multi-Cluster Allocation
Set up allocation across multiple clusters
Autoscaling
Automatically scale based on allocation demand
Session Management
Build robust session tracking with allocations
