vCluster uses a sophisticated bidirectional syncing mechanism to keep resources synchronized between the virtual cluster and the host cluster. This syncing architecture is fundamental to how vCluster operates, allowing workloads in the virtual cluster to run on the host cluster’s infrastructure while maintaining isolation.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/loft-sh/vcluster/llms.txt
Use this file to discover all available pages before exploring further.
How Syncing Works
vCluster’s syncing engine runs as part of the control plane and watches for resource changes in both the virtual and host clusters. When a resource is created, updated, or deleted, the syncer ensures the corresponding resource in the other cluster is kept in sync.Sync Architecture
The syncing system consists of several key components: Sync Controller (pkg/syncer/syncer.go:31)
The main controller that manages the reconciliation loop for each resource type. It:
- Watches resources in both virtual and host clusters
- Determines which sync operation to perform (SyncToHost, SyncToVirtual, or Sync)
- Maintains object caches for efficient comparison
- Handles UID validation and object lifecycle management
pkg/syncer/types/syncer.go:20)
Defines the contract for all resource syncers:
Sync Operations
The syncer performs three types of operations:- SyncToHost: Creates or updates a host resource based on a virtual resource
- SyncToVirtual: Creates or updates a virtual resource based on a host resource (for imported resources)
- Sync: Bidirectional sync when both resources exist
Name Translation
Resources synced from virtual to host are name-translated to prevent conflicts:- Namespace-scoped resources:
<vcluster-name>-<namespace>-<name>-x-<namespace>-x-<vcluster-name> - Cluster-scoped resources: Resources are typically not synced unless explicitly configured
vcluster.loft.sh/name: Original virtual cluster namevcluster.loft.sh/namespace: Original virtual cluster namespacevcluster.loft.sh/uid: Virtual cluster resource UID
Syncing Directions
vCluster supports two primary syncing directions:To Host (Virtual → Host)
Resources created in the virtual cluster are synced to the host cluster. This is the primary direction for workload resources. Common to-host resources:- Pods (enabled by default)
- Services (enabled by default)
- Endpoints and EndpointSlices (enabled by default)
- PersistentVolumeClaims (enabled by default)
- ConfigMaps and Secrets (selective sync by default)
- Ingresses (disabled by default)
- NetworkPolicies (disabled by default)
From Host (Host → Virtual)
Resources from the host cluster are synced into the virtual cluster. This is primarily used for cluster-level resources that workloads need to discover. Common from-host resources:- Events (enabled by default)
- Nodes (fake nodes by default, real nodes optional)
- StorageClasses (auto-enabled with scheduler)
- CSI resources (auto-enabled with scheduler)
- IngressClasses (disabled by default)
Default Synced Resources
By default, vCluster syncs these resources:To Host (Enabled)
From Host (Enabled)
Object Caching
For performance, the syncer implements object caching (pkg/syncer/syncer.go:39):
UID Validation
The syncer validates that synced resources maintain UID consistency (pkg/syncer/syncer.go:209):
- If a host object’s UID annotation doesn’t match the virtual object’s UID, the host object is deleted
- This prevents stale resources from persisting after recreation
- Can be disabled with
DisableUIDDeletionoption
Reconciliation Flow
When a resource changes, the syncer follows this flow:- Retrieve objects: Get both virtual and host versions
- Check resource versions: Ensure we’re working with latest data
- Validate UID: Ensure UID consistency
- Determine operation:
- Both exist → Sync
- Only virtual exists → SyncToHost
- Only host exists → SyncToVirtual
- Execute sync: Apply the appropriate transformation
- Update cache: Store new state for future comparisons
Configuration
Syncing behavior is configured invalues.yaml under the sync section:
Performance Considerations
- Selective ConfigMaps/Secrets: By default, only ConfigMaps and Secrets used by Pods are synced
- Object Caching: Enabled for most resources to reduce API calls
- Concurrent Reconciliation: Up to 10 concurrent reconciles per controller
- Resource Version Checking: Prevents stale object conflicts
Next Steps
- Learn about syncing to the host cluster
- Learn about syncing from the host cluster
- Configure custom resource syncing