Kubernetes Extension Pattern
Agones extends Kubernetes through two primary mechanisms:Custom Resource Definitions (CRDs)
Define game server resources like GameServer, Fleet, and GameServerAllocation as first-class Kubernetes objects
Custom Controllers
Implement reconciliation loops that manage the lifecycle of game server resources
Core Components
Agones consists of several key components that work together to manage game servers:Control Plane Components
GameServer Controller
GameServer Controller
The GameServer controller manages individual game server instances. It:
- Creates and manages Pods for each GameServer
- Monitors game server health using SDK callbacks
- Manages port allocation (Dynamic, Static, Passthrough, or None)
- Handles state transitions through the GameServer lifecycle
- Injects the Agones SDK sidecar container
pkg/gameservers/controller.goFleet Controller
Fleet Controller
The Fleet controller manages groups of GameServers using a two-level hierarchy:
- Creates and manages GameServerSets (similar to ReplicaSets)
- Implements deployment strategies (RollingUpdate, Recreate)
- Handles scaling operations
- Aggregates status from underlying GameServerSets
pkg/fleets/controller.goAllocation Controller
Allocation Controller
The Allocation controller handles game server assignment:
- Processes GameServerAllocation requests
- Implements allocation strategies (Packed, Distributed)
- Supports multi-cluster allocation
- Applies label and annotation patches
- Manages counter and list operations (Beta)
pkg/gameserverallocations/controller.goFleetAutoscaler Controller
FleetAutoscaler Controller
The FleetAutoscaler controller automatically scales Fleets based on policies:
- Buffer-based scaling (maintain a ready game server buffer)
- Webhook-based scaling (custom external logic)
- Counter-based scaling (track custom metrics)
- List-based scaling (track capacity metrics)
- Schedule-based scaling (time-based policies)
pkg/fleetautoscalers/controller.goPort Allocator
Port Allocator
The Port Allocator manages host port assignment:
- Maintains a pool of available ports per node
- Allocates ports for Dynamic and Passthrough policies
- Supports multiple port ranges (Alpha)
- Prevents port conflicts
pkg/portallocator/portallocator.goSDK Server (Sidecar)
The Agones SDK Server runs as a sidecar container alongside each game server container:Initialization
The SDK Server is automatically injected into the GameServer Pod and starts before the game server container.
Health Monitoring
Receives periodic health pings from the game server via SDK calls and reports to the controller.
State Management
Handles state transitions initiated by the game server (Ready, Allocated, Shutdown).
- gRPC:
9357(default) - HTTP:
9358(default)
pkg/sdkserver/sdkserver.go
Custom Resource Definitions
Agones defines several CRDs in theagones.dev API group:
| Resource | API Version | Purpose |
|---|---|---|
| GameServer | agones.dev/v1 | Represents a single game server instance |
| GameServerSet | agones.dev/v1 | Manages a set of identical GameServers |
| Fleet | agones.dev/v1 | High-level management of GameServerSets |
| GameServerAllocation | allocation.agones.dev/v1 | Allocates a GameServer from available pool |
| FleetAutoscaler | autoscaling.agones.dev/v1 | Automatically scales Fleets |
Control Flow
GameServer Creation Flow
Allocation Flow
High Availability
Agones controllers are designed for high availability:Agones controllers use Kubernetes leader election to ensure only one active controller manages each resource type. This prevents conflicting updates while allowing multiple controller replicas for redundancy.
- Leader election for all controllers
- Work queue-based processing with retries
- Idempotent reconciliation logic
- Graceful handling of controller restarts
Security Model
RBAC and Service Accounts
Agones uses Kubernetes RBAC to control access:Game Server Isolation
By default, game server containers have their service account tokens disabled to prevent access to the Kubernetes API: Source:gameserver.go:914-926
Scheduling Strategies
Agones supports two scheduling strategies for placing GameServers across nodes:- Packed
- Distributed
Best for: Cloud environments with autoscaling nodesBehavior: Concentrates GameServers on fewer nodes to maximize resource utilization and minimize infrastructure costs.Implementation: Uses pod affinity to prefer nodes already running GameServers.
Observability
Metrics
Agones exports Prometheus metrics for monitoring:- GameServer metrics: State distribution, creation/deletion rates
- Fleet metrics: Replica counts (ready, allocated, reserved)
- Allocation metrics: Request rates, latencies, success/failure counts
- Autoscaler metrics: Scaling decisions, buffer states
8080 (default)
Events
Agones generates Kubernetes Events for important state changes:Next Steps
GameServer Lifecycle
Understand GameServer states and lifecycle management
Fleet Management
Learn about managing groups of GameServers
Allocation System
Explore how to allocate GameServers to players
Autoscaling
Set up automatic scaling for your Fleets
