Synchronize labels between vCluster and the host cluster
In vCluster version 0.20 or earlier, labels are not automatically synchronized to the host cluster. This affects:
- Monitoring systems that rely on labels.
- Logging solutions that filter based on labels.
- Service discovery mechanisms that use label selectors.
- Other label-dependent workflows.
Solution​
For vCluster 0.21.x and later​
All labels are synchronized by default between the virtual cluster and host cluster. No additional configuration is required.
For vCluster versions earlier than 0.21.x​
You must explicitly configure which labels to synchronize using the experimental.syncSettings.syncLabels
feature:
experimental:
syncSettings:
syncLabels:
- 'namespace' # Sync labels related to namespaces
- 'example.com/*' # Sync all labels with the 'example.com/' prefix
- 'example.com/' # Sync a specific label starting with 'example.com/'
Apply label synchronization configuration​
Add the configuration to your vCluster values file.
Create or edit your
values.yaml
file to include the label synchronization settings:experimental:
syncSettings:
syncLabels:
- 'namespace' # Sync labels related to namespaces
- 'example.com/*' # Sync all labels with the 'example.com/' prefix
- 'example.com/' # Sync a specific label starting with 'example.com/'Apply the configuration to your vCluster.
-
For a new vCluster:
vcluster create my-vcluster -n my-namespace -f values.yaml
-
For an existing vCluster:
vcluster update my-vcluster -n my-namespace -f values.yaml
-
Check that the configuration was applied.
View the vCluster configuration:
kubectl get configmap -n my-namespace vcluster-my-vcluster -o yaml
Verify that the label synchronization settings appear in the configuration.
Confirm label synchronization is working​
To verify that label synchronization is working:
# Get a pod from the vCluster
kubectl get pod my-pod -o jsonpath='{.metadata.labels}'
# Connect to the host cluster
kubectl config use-context host-context
# Check the corresponding pod in the host cluster
kubectl get pod vcluster-my-pod-my-vcluster -n my-namespace -o jsonpath='{.metadata.labels}'
Compare the labels between the two outputs to confirm synchronization.