Nodes
This feature is only available when using the following worker node types:
By default, this is disabled by default. vCluster only displays nodes in the virtual cluster if the virtual cluster has synced pods to that worker node from the host. If there are no more pods on a node, vCluster deletes the node. Without syncing the nodes, these nodes are considered pseudo nodes as the name is the only real value, and the rest of the nod information is randomly generated.
If you need specific node informatin, enabling to sync nodes from the host will allow the real information from the node to be available from the virtual cluster context. In order to access node informatin, a cluster role is deployed onto the host cluster.
By default, vCluster obfuscates node IP addresses when syncing real nodes to protect sensitive information. Learn how to control node IP visibility for your use case.
Selecting a set of nodesβ
By default, vCluster is able to schedule pods to any of the worker nodes in the host cluster, but you can isolate a virtual cluster to only use a set of specific nodes from the host cluster. There are multiple reasons why you may want to dedicate nodes to a virtual cluster including:
- Restricting vCluster to nodes in a specific region.
- Targeting nodes with a particular architecture.
- Using only spot or preemptible instances.
- Preventing vCluster workloads from running on critical infrastructure nodes.
Selecting nodes is based on a node label selector, where the nodes on the host cluster must have the matching labels.
Select a set of nodes without syncing node informationβ
If you don't want to sync node information, you can still select to use only a set of nodes from the host cluster.
sync:
fromHost:
nodes:
# Do not sync real node information
enabled: false
# Select a set of nodes based on the node labels
selector:
labels:
environment: production
team: backend
Select a set of nodes and sync node informationβ
You can select a set of nodes from the host cluster while also requesting that the nodes sync with the real information from the host cluster.
sync:
fromHost:
nodes:
# Sync real node information
enabled: true
# Select a set of nodes based on the node labels
selector:
labels:
environment: production
team: backend
Sync real nodesβ
Sync nodes to the virtual cluster in order to view real node information. The virtual cluster will only display the host nodes that have a pod deployed onto it. By enabling this sync, a cluster role is deployed by the vCluster onto the host cluster.
sync:
fromHost:
nodes:
enabled: true
Sync all real nodesβ
When syncing nodes, only nodes that have pods deployed on them will show up in the virtual cluster, but you can
sync all the nodes from the host cluster. When selecting all the nodes, kubectl get nodes
will display
all the host nodes whether or not a pod has been scheduled onto the host cluster.
sync:
fromHost:
nodes:
enabled: true
selector:
all: true
Sync back labels and taintsβ
By default, when syncing nodes from the host cluster, labels and taints are only synced from the host cluster to the virtual cluster. No changes from the virtual cluster context would be reflected on the host nodes.
Enabling syncBackChanges
allows labels and taints set from the virtual cluster context to be synced to the host nodes. Additional
permissions are added to the cluster role in order to edit the host nodes.
sync:
fromHost:
nodes:
enabled: true
syncBackChanges: true
Hide image informationβ
When multiple tenants are using the same set of host nodes, container image metadata could be used maliciously. For increased security,
you can enable clearImageStatus
to remove all status.images
from the node object.
sync:
fromHost:
nodes:
enabled: true
clearImageStatus: true
Patchesβ
This feature is an Enterprise feature. See our pricing plans or contact our sales team for more information.
Patches override the default resource syncing rules in your vCluster yaml configurations.
By default, vCluster syncs specific resources between virtual and host clusters. To modify the sync behavior, you can use patches to specify which fields to edit, exclude, or override during syncing.
For example, vCluster can mirror resources from the virtual cluster to the host clusterβany changes made in the virtual cluster are automatically applied to the host cluster. The same applies in the other direction if syncing is set up from host to virtual cluster.
vCluster supports two patch types:
- JavaScript expression patch: Uses JavaScript ES6 expressions to dynamically modify fields during syncing. You can define how a field changes when syncing from a virtual cluster to a host cluster, or from a host cluster to a virtual cluster.
- Reference patch: Modifies specific fields within a resource to point to different resources. If the referenced resource exists in the host cluster, vCluster automatically imports it into the virtual cluster. If the referenced resource exists in the virtual cluster and syncing is configured, vCluster can import it into the host cluster.
You can apply a wildcard, using an asterisk (*
) in a specified path, to modify all elements of an array or object.
For instance, spec.containers[*].name
selects the name
field of every container in the spec.containers
array, and spec.containers[*].volumeMounts[*]
selects all volumeMounts
for each container.
When using the asterisk (*
) notation, vCluster applies changes individually to every element that matches the path.
JavaScript expression patchβ
A JavaScript expression patch allows you to use JavaScript ES6 expressions to change specific fields when syncing between virtual and host clusters. This is useful when modifying resource configurations to align with differing environments or naming conventions between clusters. If your clusters use different container name prefixes, a JavaScript expression patch can automatically update them.
You can define a path for status.nodeInfo.operatingSystem
field in vcluster.yaml
using the following configuration:
sync:
fromHost:
nodes:
enabled: true
patches:
- path: status.nodeInfo.operatingSystem
expression: '"my-prefix-"+value'
# optional reverseExpression to reverse the change from the host cluster
# reverseExpression: 'value.slice("my-prefix".length)'
In the example:
- The path targets the
status.nodeInfo.operatingSystem
field to override when syncing to the host cluster. The*
wildcard applies the patch to each container individually. "'my-prefix-' + value"
defines a JavaScript expression that prepends"my-prefix-"
to thestatus.nodeInfo.operatingSystem
field in the host cluster.
If the path
in a patch references a field where the parent object is null
or doesn't exist, vCluster logs an error in the vCluster container but it does not block the synchronization to the host.
For example, if you specify path: spec.template.metadata.labels["my-label"]
but spec.template
is null
, the patch fails and you'll see an error in the vCluster logs.
You can use the reverseExpression
field to define how to revert changes when syncing from the host cluster back to the virtual cluster.
For example, add reverseExpression: {"value.slice('my-prefix'.length)"}
to vcluster.yaml
to remove the "my-prefix-"
prefix when syncing back from the host cluster to the virtual cluster in the previous example.
To replace value with a hardcoded one, put the desired value in the quotation marks:
sync:
fromHost:
nodes:
enabled: true
patches:
- path: status.nodeInfo.operatingSystem
expression: '"my-value"'
Adding new keys in maps like annotations or labels to the resource is also possible with expressions. For example, to add a label to the resource in the host cluster, you can use:
sync:
toHost:
nodes:
enabled: true
patches:
- path: metadata.label["my-new-label"]
expression: 'valueExists ? value + "-changed" : "new-label-value"'
The value
variable in the case where the map entry does not exist is null
.
To distinguish between an entry that does not exist and an entry that exists with a null
value, you can use the valueExists
variable in your expression.
The valueExists
variable is true
if the entry exists in the map, even if its value is null
.
The keys can also be conditionally added based on the value returned by the expression. If the expression evaluates to null
, the key is not added to the map.
Here is an example of conditionally adding a label based on the existence of another label:
sync:
toHost:
nodes:
enabled: true
patches:
- path: metadata.labels["conditional-label"]
expression: "context.virtualObject.metadata?.label?.['my-label'] ? 'my-value' : null"
The above example checks if the my-label
label exists in the virtual object. If it does, it adds the conditional-label
with the value my-value
. If it does not exist, it does not add the label.
The JavaScript expression patch supports a limited set of JavaScript features. For example, it does not support import
statements or other Node.js-specific features. You can use standard JavaScript expressions, functions, and operators.
The expression is evaluated in a sandboxed environment, so it cannot access external resources or the host system.
Also, the JavaScript expression must be a valid ES6 expression. This means it should not contain any statements, only expressions that return a value.
A common use is to use ternary operators to conditionally modify values based on their existence or other criteria.
Another common use is the optional chaining operator
like in: value.myfield?.anotherfield || "default-value"
.
Additional functions available:
atob(encodedData)
: Decodes a base64-encoded string and returns the decoded string. Ex:atob("bXktdmFsdWU=")
returnsmy-value
.btoa(stringToEncode)
: Encodes a string in base64 and returns the encoded string. Ex:btoa("my-value")
returnsbXktdmFsdWU=
.
These functions are useful for encoding/decoding values when syncing between clusters:
sync:
toHost:
nodes:
enabled: true
patches:
- path: metadata.annotations["encoded-value"]
expression: 'btoa(value)'
- path: metadata.annotations["decoded-value"]
expression: 'atob(value)'
Context variableβ
The context variable is an object supported in JavaScript expression patches, that provides access to virtual cluster data during syncing. The context object includes the following properties:
context.vcluster.name
: Name of the virtual cluster.context.vcluster.namespace
: Namespace of the virtual cluster.context.vcluster.config
: Configuration of the virtual cluster, basicallyvcluster.yaml
merged with the defaults.context.hostObject
: Host object (null
if not available).context.virtualObject
: Virtual object (null
if not available).context.path
: Matched path on the object, useful when using wildcard path selectors (*
).
Reference patchβ
A reference patch links a field in one resource to another resource. During syncing, vCluster updates the reference and imports the linked resource from the virtual cluster to the host cluster or from the host cluster to the virtual cluster, depending on the sync direction and whether the resource exists.
You can use reference patches to share resources, such as Secrets
or ConfigMaps
, between clusters without manually recreating or duplicating them.
For example, if the host cluster contains a secret named "my-example-secret"
, vCluster automatically imports it into the virtual cluster.
Workloads in the virtual cluster can then use the secret without manual syncing.
You can sync between the virtual cluster and the host cluster by mapping spec.secretName
to a secret in the host cluster:
sync:
toHost:
nodes:
enabled: true
patches:
- path: metadata.annotations["my-secret-ref"]
reference:
apiVersion: v1
kind: Secret
In the example:
- The code uses a patch to add
metadata.annotations["my-secret-ref"]
- It references a
Secret
in the host cluster using the patch and ensuresnodes
in the host cluster links to the correctSecret
.
::: Reference Patches with Namespace Syncing
If you have enabled syncing namespaces, reference patches are only required if the namespace is part of the patch. You can use the namespacePath
option to specify the path of the namespace of the reference.
:::
Config referenceβ
nodes
required object β
Nodes defines if nodes should get synced from the host cluster to the virtual cluster, but not back.
nodes
required object βenabled
required boolean false β
Enabled specifies if syncing real nodes should be enabled. If this is disabled, vCluster will create fake nodes instead.
enabled
required boolean false βsyncBackChanges
required boolean false β
SyncBackChanges enables syncing labels and taints from the virtual cluster to the host cluster. If this is enabled someone within the virtual cluster will be able to change the labels and taints of the host cluster node.
syncBackChanges
required boolean false βclearImageStatus
required boolean false β
ClearImageStatus will erase the image status when syncing a node. This allows to hide images that are pulled by the node.
clearImageStatus
required boolean false βselector
required object β
Selector can be used to define more granular what nodes should get synced from the host cluster to the virtual cluster.
selector
required object βall
required boolean false β
All specifies if all nodes should get synced by vCluster from the host to the virtual cluster or only the ones where pods are assigned to.
all
required boolean false βlabels
required object {} β
Labels are the node labels used to sync nodes from host cluster to virtual cluster. This will also set the node selector when syncing a pod from virtual cluster to host cluster to the same value.
labels
required object {} βpatches
required object[] β
Patches patch the resource according to the provided specification.
patches
required object[] βpath
required string β
Path is the path within the patch to target. If the path is not found within the patch, the patch is not applied.
path
required string βexpression
required string β
Expression transforms the value according to the given JavaScript expression.
expression
required string βreverseExpression
required string β
ReverseExpression transforms the value according to the given JavaScript expression.
reverseExpression
required string βreference
required object β
Reference treats the path value as a reference to another object and will rewrite it based on the chosen mode
automatically. In single-namespace mode this will translate the name to "vxxxxxxxxx" to avoid conflicts with
other names, in multi-namespace mode this will not translate the name.
reference
required object βapiVersion
required string β
APIVersion is the apiVersion of the referenced object.
apiVersion
required string βapiVersionPath
required string β
APIVersionPath is optional relative path to use to determine the kind. If APIVersionPath is not found, will fallback to apiVersion.
apiVersionPath
required string βkind
required string β
Kind is the kind of the referenced object.
kind
required string βkindPath
required string β
KindPath is the optional relative path to use to determine the kind. If KindPath is not found, will fallback to kind.
kindPath
required string βnamePath
required string β
NamePath is the optional relative path to the reference name within the object.
namePath
required string βnamespacePath
required string β
NamespacePath is the optional relative path to the reference namespace within the object. If omitted or not found, namespacePath equals to the
metadata.namespace path of the object.
namespacePath
required string βlabels
required object β
Labels treats the path value as a labels selector.
labels
required object β