GameServer is the fundamental building block in Agones. It represents a single dedicated game server instance running in your Kubernetes cluster, complete with networking, health checking, and lifecycle management.
GameServer Resource
The GameServer CRD combines Kubernetes Pod management with game-server-specific features:Lifecycle States
GameServers progress through a well-defined lifecycle. Understanding these states is crucial for building robust game server systems.State Diagram
State Definitions
Source:pkg/apis/agones/v1/gameserver.go:38-75
- Pre-Ready States
- Active States
- Terminal States
PortAllocation
When: GameServer has Dynamic or Passthrough port policiesWhat happens: The port allocator assigns host ports from the available poolDuration: Typically milliseconds
Creating
When: Before the Pod is createdWhat happens: GameServer controller prepares Pod specification with SDK sidecarDuration: Usually < 1 second
Starting
When: Pod is created but not yet scheduledWhat happens: Kubernetes scheduler finds a suitable nodeDuration: Depends on cluster capacity
Scheduled
When: Pod has been assigned to a nodeWhat happens: Kubelet pulls images and starts containersDuration: Varies based on image size and node resources
Port Configuration
Agones provides flexible port management with four port policies:Port Policies
Source:gameserver.go:77-92
Dynamic (Default)
Dynamic (Default)
The system automatically allocates an available host port.Configuration:Behavior:
hostPortis automatically assigned from the available poolcontainerPortremains as specified- Port mapping is created:
hostPort→containerPort
Static
Static
You specify both host and container ports explicitly.Configuration:Behavior:
- Both ports are as specified
- You must ensure the hostPort is available
- Required for development GameServers (with dev-address annotation)
gameserver.go:566-568Passthrough
Passthrough
The containerPort is dynamically set to match the allocated hostPort.Configuration:Behavior:
- System allocates a
hostPort containerPortis set to the same value- Game server must query SDK for the actual port:
SDK.WatchGameServer()
gameserver.go:88-89None (Beta)
None (Beta)
No host port is allocated; only the container port is configured.Configuration:Behavior:
- No
hostPortmapping is created - Only
containerPortis configured in the container - Useful for non-networked game servers or custom networking
PortPolicyNoneSource: gameserver.go:90-91Protocol Support
Agones supports multiple network protocols:gameserver.go:124-125
Port Ranges (Alpha)
You can define custom port ranges for better organization:PortRanges
Health Checking
Agones monitors GameServer health through SDK callbacks:gameserver.go:414-426):
- Default period: 5 seconds
- Default failure threshold: 3 consecutive failures
- Default initial delay: 5 seconds
- If
Health()is not called within period × failureThreshold, GameServer becomes Unhealthy
Health checking is based on SDK callbacks, not Kubernetes liveness/readiness probes. Your game server must call
SDK.Health() periodically.Counters and Lists (Beta)
Counters and Lists provide flexible capacity tracking for game sessions:Counters
Track integer values (e.g., player count, room count):gameserver.go:1003-1048):
UpdateCount(): Increment or decrementUpdateCounterCapacity(): Change maximum capacity- Automatically clamped to [0, capacity]
Lists
Track string values (e.g., player IDs, session tokens):gameserver.go:1065-1098):
AppendListValues(): Add unique valuesDeleteListValues(): Remove specific valuesUpdateListCapacity(): Change maximum capacity- Maximum capacity: 1000 items per list
CountsAndLists
SDK Server Configuration
The Agones SDK Server runs as a sidecar and can be configured:gameserver.go:109-121):
Info(default): Standard operational messagesDebug: Includes debug informationError: Only error messagesTrace: Detailed tracing for troubleshooting
Eviction Control
Control whether GameServers can be evicted during node maintenance:gameserver.go:94-107):
- Never (Default)
- OnUpgrade
- Always
GameServer should run to completion. Blocks both cluster autoscaler scale-down and node upgrades.Best for: Game sessions that cannot be interrupted
Scheduling Strategy
Choose how GameServers are distributed across nodes:- Packed (default): Concentrates GameServers on fewer nodes
- Distributed: Spreads GameServers evenly across nodes
gameserver.go:475-479, gameserver.go:889-912
Working with GameServers
Create a GameServer
Check GameServer Status
View GameServer Details
Delete a GameServer
Best Practices
Always use health checks
Disable only for testing. Production GameServers should implement health checking.
Call SDK.Ready() explicitly
Don’t rely on automatic readiness. Signal when your game server is fully initialized.
Handle SDK.Shutdown() gracefully
Save game state and close connections before exiting.
Use Dynamic port policy
Simplifies deployment and prevents port conflicts.
Next Steps
Fleets
Learn about managing groups of GameServers
Allocation
Allocate GameServers to players
SDK Integration
Integrate the Agones SDK into your game server
Port Policy Guide
Deep dive into port configuration options
