LoadBalancer Controller
Overview
The LoadBalancer controller reconcilesLoadBalancer custom resources and manages Layer 4 load balancing services in the management cluster.
Controller Name: loadbalancer-controller
Location: internal/controllers/kubelb/loadbalancer_controller.go:68
What It Does
- Creates and manages Kubernetes Services (LoadBalancer type) for L4 traffic
- Allocates unique NodePorts for each load balancer endpoint
- Configures hostname-based load balancing via Ingress or HTTPRoute resources
- Performs health checks for DNS resolution and TLS endpoints
- Synchronizes load balancer status back to tenant clusters
- Manages service annotations and labels based on tenant/global configuration
Resources Watched
LoadBalancer (kubelb.k8c.io/v1alpha1)
LoadBalancer (kubelb.k8c.io/v1alpha1)
Service (core/v1)
Service (core/v1)
kubelb.k8c.io/loadbalancer-name to track status changes and propagate them back to LoadBalancer resources.Config (kubelb.k8c.io/v1alpha1)
Config (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Reconciliation Behavior
- Validation: Ensures LoadBalancer has at least one endpoint defined
- Tenant/Config Lookup: Retrieves tenant and global configuration
- Reconcilability Check: Verifies L4 load balancing is enabled at both tenant and global levels
- Finalizer Management: Adds
kubelb.k8c.io/cleanupfinalizer for cleanup coordination - Port Allocation: Allocates unique NodePorts via the PortAllocator
- Service Creation/Update: Creates or updates the Kubernetes Service with:
- Proper selector labels pointing to the Envoy proxy pods
- Port mappings (LoadBalancer ports to allocated NodePorts)
- Load balancer class (if specified in Tenant or Config)
- Annotations from tenant/global configuration
- Hostname Configuration (if enabled):
- Generates or uses specified hostname
- Creates either an Ingress or HTTPRoute resource for hostname routing
- Performs DNS resolution health checks
- Performs TLS endpoint health checks
- Status Update: Updates LoadBalancer status with:
- Service port mappings
- Load balancer ingress IPs/hostnames
- Hostname status (if configured)
Cleanup Process
- Deallocates ports from the PortAllocator
- Deletes hostname resources (Ingress or HTTPRoute)
- Deletes the Kubernetes Service
- Removes all finalizers
RBAC Permissions
Route Controller
Overview
The Route controller reconcilesRoute custom resources that represent Layer 7 routing configurations (Ingress, Gateway API resources).
Controller Name: route-controller
Location: internal/controllers/kubelb/route_controller.go:64
What It Does
- Manages Layer 7 routing resources (Ingress, Gateway, HTTPRoute, GRPCRoute)
- Creates NodePort services for backend pods in the management cluster
- Allocates unique NodePorts for each service endpoint
- Propagates status from management cluster back to Route resources
- Handles cleanup of orphaned services when routes change
Resources Watched
Route (kubelb.k8c.io/v1alpha1)
Route (kubelb.k8c.io/v1alpha1)
Config (kubelb.k8c.io/v1alpha1)
Config (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Ingress (networking.k8s.io/v1)
Ingress (networking.k8s.io/v1)
Gateway (gateway.networking.k8s.io/v1)
Gateway (gateway.networking.k8s.io/v1)
HTTPRoute (gateway.networking.k8s.io/v1)
HTTPRoute (gateway.networking.k8s.io/v1)
GRPCRoute (gateway.networking.k8s.io/v1)
GRPCRoute (gateway.networking.k8s.io/v1)
Reconciliation Behavior
- Tenant/Config Lookup: Retrieves tenant and global configuration
- Resource Type Detection: Determines route type (Ingress/Gateway/HTTPRoute/GRPCRoute)
- Reconcilability Check: Verifies the corresponding feature is enabled:
- For Ingress: checks if Ingress is enabled
- For Gateway API: checks if Gateway API is enabled
- For Gateway: validates the gateway name is “kubelb”
- Finalizer Management: Adds
kubelb.k8c.io/cleanupfinalizer - Service Management:
- Allocates NodePorts for all referenced services
- Creates/updates NodePort services in the management cluster
- Cleans up orphaned services no longer referenced
- Cleans up services from old naming scheme
- Route Resource Management:
- Creates or updates the routing resource (Ingress/Gateway/HTTPRoute/GRPCRoute)
- Sets owner references for proper cleanup
- Transforms service references to point to management cluster services
- Status Propagation: Reads status from created resources and updates Route status
Cleanup Process
- Deletes all NodePort services created for the route
- Deallocates ports from the PortAllocator
- Removes finalizer (routes are deleted via owner references)
RBAC Permissions
EnvoyCP Controller
Overview
The EnvoyCP (Envoy Control Plane) controller manages the Envoy xDS (discovery service) configuration and Envoy proxy deployments/daemonsets. Controller Name:envoy-cp-controller
Location: internal/controllers/kubelb/envoy_cp_controller.go:60
What It Does
- Generates and updates Envoy xDS snapshots with cluster, listener, endpoint, route, and secret configurations
- Manages Envoy proxy Deployment or DaemonSet resources
- Configures graceful shutdown for Envoy proxies using a shutdown manager sidecar
- Handles Envoy bootstrap configuration generation
- Tracks snapshot versions and ensures consistency before applying updates
Resources Watched
LoadBalancer (kubelb.k8c.io/v1alpha1)
LoadBalancer (kubelb.k8c.io/v1alpha1)
Route (kubelb.k8c.io/v1alpha1)
Route (kubelb.k8c.io/v1alpha1)
Addresses (kubelb.k8c.io/v1alpha1)
Addresses (kubelb.k8c.io/v1alpha1)
Config (kubelb.k8c.io/v1alpha1)
Config (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Reconciliation Behavior
- Config Retrieval: Fetches latest Config to use for Envoy configuration
- Resource Listing: Lists all LoadBalancers and Routes in the tenant namespace
- Cleanup Check: If no LoadBalancers or Routes exist:
- Clears the Envoy snapshot from cache
- Deletes the Envoy proxy Deployment/DaemonSet
- Envoy Proxy Management: Creates or updates Envoy proxy Deployment/DaemonSet with:
- Configured image (or default
envoyproxy/envoy:distroless-v1.36.4) - Bootstrap configuration via command-line args
- Readiness, liveness, and startup probes
- Optional graceful shutdown manager sidecar
- Resource limits/requests from Config
- Affinity, tolerations, node selector from Config
- Optional single-pod-per-node topology spread
- Configured image (or default
- Port Allocation: Allocates ports for all LoadBalancers and Routes
- Snapshot Generation: Creates Envoy xDS snapshot with:
- Clusters (upstream endpoints)
- Listeners (ingress points)
- Endpoints (backend node addresses)
- Routes (L7 routing rules)
- Secrets (TLS certificates)
- Snapshot Update: Updates the Envoy cache with new snapshot after consistency check
Configuration Options
The controller uses settings from theConfig resource’s spec.envoyProxy section:
image: Custom Envoy image (default:envoyproxy/envoy:distroless-v1.36.4)useDaemonset: Deploy as DaemonSet instead of Deployment (default: false)replicas: Number of replicas for Deployment mode (default: 3)resources: Resource requests/limits for Envoy containeraffinity: Pod affinity/anti-affinity rulestolerations: Pod tolerationsnodeSelector: Node selector for pod placementsinglePodPerNode: Enable topology spread to distribute one pod per nodegracefulShutdown: Graceful shutdown configuration:disabled: Disable graceful shutdown (default: false)drainTimeout: Time to drain connections (default: 30s)terminationGracePeriodSeconds: Pod termination grace period (default: 60s)shutdownManagerImage: Shutdown manager sidecar image
RBAC Permissions
SyncSecret Controller
Overview
The SyncSecret controller convertsSyncSecret custom resources into standard Kubernetes Secret resources in the management cluster.
Controller Name: sync-secret-controller
Location: internal/controllers/kubelb/sync_secret_controller.go:46
What It Does
- Synchronizes secrets from tenant clusters to the management cluster
- Creates Kubernetes Secrets with randomized names (using SyncSecret UID)
- Maintains secret data, type, labels, and annotations
- Sets owner references for automatic cleanup
Resources Watched
SyncSecret (kubelb.k8c.io/v1alpha1)
SyncSecret (kubelb.k8c.io/v1alpha1)
Reconciliation Behavior
- Finalizer Management: Adds
kubelb.k8c.io/cleanupfinalizer - Secret Creation: Creates a Kubernetes Secret with:
- Name set to the SyncSecret’s UID (for uniqueness)
- Namespace matching the SyncSecret
- Data and StringData from SyncSecret spec
- Type from SyncSecret spec
- Labels and annotations from SyncSecret
- Owner reference pointing to the SyncSecret
- Secret Update: Updates existing Secret if data, type, labels, or annotations change
Cleanup Process
- Deletes the associated Kubernetes Secret
- Removes finalizer from SyncSecret
RBAC Permissions
Tenant Controller
Overview
The Tenant controller manages tenant isolation and provides each tenant with a dedicated namespace and credentials to communicate with the management cluster. Controller Name:tenant-controller
Location: internal/controllers/kubelb/tenant_controller.go:87
What It Does
- Creates dedicated namespaces for each tenant (format:
tenant-{name}) - Sets up RBAC (ServiceAccount, Role, RoleBinding) for tenant access
- Generates kubeconfig files for tenants to access their namespace
- Creates TenantState resources tracking tenant configuration status
- Handles cleanup of all tenant resources on deletion
Resources Watched
Tenant (kubelb.k8c.io/v1alpha1)
Tenant (kubelb.k8c.io/v1alpha1)
Reconciliation Behavior
- Finalizer Management: Adds
kubelb.k8c.io/cleanupfinalizer - Namespace Creation: Creates namespace named
tenant-{tenantName}with owner reference - RBAC Setup:
- Creates ServiceAccount for tenant operations
- Creates Role with permissions to manage LoadBalancers, Routes, and SyncSecrets
- Creates RoleBinding linking ServiceAccount to Role
- Creates Secret with ServiceAccount token
- Kubeconfig Generation:
- Retrieves ServiceAccount token and CA certificate
- Determines Kubernetes API server URL (from cluster-info ConfigMap or endpoints)
- Generates kubeconfig with tenant namespace context
- Stores kubeconfig in a Secret in the tenant namespace
- TenantState Management:
- Creates/updates TenantState resource with current configuration
- Tracks version information
- Records enabled/disabled features (LoadBalancer, Ingress, Gateway API)
Cleanup Process
When a Tenant is deleted:- Deletes all Routes in tenant namespace
- Deletes all LoadBalancers in tenant namespace
- Deletes all SyncSecrets in tenant namespace
- Waits for all resources to be fully deleted (requeues if any remain)
- Deletes namespace, ServiceAccount, Role, RoleBinding, and Secrets
- Removes finalizer from Tenant
RBAC Permissions
Manager Flags
The KubeLB Manager binary (kubelb) supports the following command-line flags:
Core Configuration
| Flag | Default | Description |
|---|---|---|
--listen-address | :8001 | Address to serve Envoy control-plane xDS API |
--metrics-addr | :9443 | Address for Prometheus metrics endpoint |
--health-probe-bind-address | :8081 | Address for health and readiness probes |
--namespace | kubelb | Namespace where the controller runs |
--kubeconfig | (empty) | Path to kubeconfig (only required if out-of-cluster) |
Feature Flags
| Flag | Default | Description |
|---|---|---|
--enable-leader-election | true | Enable leader election for high availability |
--enable-gateway-api | false | Enable Gateway API support (requires Gateway API CRDs) |
--debug | false | Enable debug mode for detailed logging |
Deprecated Flags
| Flag | Status | Description |
|---|---|---|
--enable-tenant-migration | NOOP | Tenant migration controller has been deprecated and removed |
Environment Variables
| Variable | Description |
|---|---|
NAMESPACE | Alternative to --namespace flag for specifying controller namespace |
Metrics
The Manager controllers expose Prometheus metrics on the configured metrics address (default:9443).
LoadBalancer Metrics
kubelb_manager_loadbalancer_reconcile_total- Total LoadBalancer reconciliations by resultkubelb_manager_loadbalancer_reconcile_duration_seconds- LoadBalancer reconciliation durationkubelb_manager_loadbalancers_total- Current number of LoadBalancers per tenant
Route Metrics
kubelb_manager_route_reconcile_total- Total Route reconciliations by type and resultkubelb_manager_route_reconcile_duration_seconds- Route reconciliation durationkubelb_manager_routes_total- Current number of Routes per tenant and type
EnvoyCP Metrics
kubelb_manager_envoycp_reconcile_total- Total EnvoyCP reconciliationskubelb_manager_envoycp_reconcile_duration_seconds- EnvoyCP reconciliation durationkubelb_manager_envoycp_snapshot_updates_total- Envoy snapshot updates per tenantkubelb_manager_envoycp_clusters- Envoy clusters in current snapshotkubelb_manager_envoycp_listeners- Envoy listeners in current snapshotkubelb_manager_envoycp_endpoints- Envoy endpoints in current snapshotkubelb_manager_envoy_proxies_total- Current number of Envoy proxy deployments
Tenant Metrics
kubelb_manager_tenant_reconcile_total- Total Tenant reconciliationskubelb_manager_tenant_reconcile_duration_seconds- Tenant reconciliation durationkubelb_manager_tenants_total- Current number of active tenants
SyncSecret Metrics
kubelb_manager_syncsecret_reconcile_total- Total SyncSecret reconciliationskubelb_manager_syncsecret_reconcile_duration_seconds- SyncSecret reconciliation duration
