Load Balancers
Nstance supports automatic registration/de-registration of instances with cloud provider load balancers.
Configuration
Load balancers are defined in the load_balancers configuration section:
{
"load_balancers": {
"www": {
"provider": "aws",
"target_group_arns": [
"arn:aws:elasticloadbalancing:region:account:targetgroup/www-80/123",
"arn:aws:elasticloadbalancing:region:account:targetgroup/www-443/456"
]
},
"internal": {
"provider": "gcp",
"backend_service_name": "internal-backend",
"instance_group_name": "internal-ig"
}
},
"groups": {
"web-servers": {
"template": "web",
"size": 3,
"load_balancers": ["www"]
},
"api-servers": {
"template": "api",
"size": 2,
"load_balancers": ["www", "internal"]
}
}
}Provider-Specific Fields:
- AWS:
target_group_arns(required) - Array of NLB target group ARNs. For multi-port NLBs, include one ARN per port/listener. The server registers instances with all specified target groups. - GCP:
backend_service_name(required),instance_group_name(required) - Backend service and unmanaged instance group names. Instances are added to the instance group once (GCP instance groups are not port-specific).
Lifecycle Integration
Registration Flow:
- Instance created via provider API
- Agent registers and sends first health report to server
- Server registers instance with all configured load balancer groups for its group
- Status tracked in
lb_instancestable:pending→registered(orfailed) - Failed registrations retried on subsequent health reports
Deregistration Flow:
- Instance marked for deletion (unhealthy, expired, or scale-down)
- Deregister from load balancer groups (first, per explicit ordering)
- Drain coordination with Operator (if Kubernetes node)
- Terminate instance via provider API (once drained, if Kubernetes node)
Reconciliation & Cache Management:
- Automatic retries: Pending or failed registrations are retried on every health report
- Leader election validation: On leader election, all LB groups are validated and cache warmed from provider APIs by querying each load balancer’s current instance list
- Cache table:
lb_instancesis a reconciliation cache tracking registration state; it’s synced from provider APIs during validation - Eventual consistency: Ensures correct state even after Nstance Server leadership changes or crashes