Virtual Clusters
A virtual cluster is a fully functional Kubernetes cluster that runs inside the namespace of another Kubernetes cluster (host cluster). Virtual clusters are very useful if you are hitting the limits of namespaces and do not want to make special exceptions to the multi-tenancy configuration of the underlying cluster, e.g. a user needs their own CRD or user needs pods from 2 namespaces to communicate with each other but your standard NetworkPolicy does not allow this, then a virtual cluster may be perfect for this user.
Working with Virtual Clusters
Unlike "real" clusters, virtual clusters are much more lightweight and much faster to spin up and tear down again.
Create Virtual Clusters
- UI
- CLI
- kubectl
- Go to the Virtual Clusters view using the menu on the left
- Click on the button
- Use the field Display Name to define the name of this virtual cluster and optionally specify other settings
- Click on the button at the very bottom
Retrieve a kube-context for this virtual cluster using Loft CLI:
loft use vcluster [vcluster-name]
To create a virtual cluster using Loft CLI, run:
loft create vcluster [vcluster-name]
Kube-Context
Running loft create vcluster
will automatically add a kube-context to your kube-config file, so you can immediately run kubectl
commands right after creating a virtual cluster.
If you do not have a kube-context for the cluster where this space should be created in, you can set up a kube-context using:
loft use cluster [cluster-name]
Create a file named
vcluster.yaml
with the following content:apiVersion: cluster.loft.sh/v1
kind: VirtualCluster
metadata:
name: vcluster-name # Set the name for your virtual cluster here
namespace: vc-host-namespace # Host namespace for the virtual clusterCreate the virtual cluster using kubectl:
kubectl apply -f vcluster.yaml
Retrieve a kube-context for this virtual cluster using Loft CLI:
loft use vcluster [vcluster-name]
Delete Virtual Clusters
- UI
- CLI
- kubectl
- In the Virtual Clusters view, hover over the row of the virtual cluster that you want to delete.
- While hovering over the row, you will see buttons appear on the right in the Actions column
- Click on the button to Delete the virtual cluster
loft delete vcluster [vcluster-name]
Kube-Context
Deleting virtual clusters with Loft CLI has the advantage that Loft CLI will also delete the kube-context for this virtual cluster from your local kube-config file to keep everything cleaned up.
If you do not have a kube-context for the cluster where this virtual cluster is located in, you can set up a kube-context using:
loft use cluster [cluster-name]
Delete the virtual cluster using kubectl:
kubectl delete vcluster [vcluster-name]
# Alternatives:
# 1) kubectl delete space [host-namespace] # Delete the host namespace
# 2) kubectl delete -f vcluster.yaml
List Virtual Clusters
- UI
- CLI
- kubectl
To see a list of virtual clusters, go to the Virtual Clusters view using the main menu on the left.
Run this command using Loft CLI to get a list of all virtual clusters you have access to across all clusters:
loft list vclusters
Kube-Context
If you want to retrieve a kube-context for any of your virtual clusters, run:
loft use vcluster [vcluster-name]
If you do not have a kube-context for the space (host namespace) where you want to list virtual clusters in, you can set up a kube-context using:
loft use space [space-name]
Run this kubectl command to get a list of virtual clusters in this namespace:
kubectl get virtualclusters
Control Access To Virtual Cluster
- UI
- CLI
- In the Virtual Clusters view, hover over virtual cluster that you want to give someone access to
- While hovering over the row, you will see buttons appear on the right in the Actions column
- Click on the button to Edit the virtual cluster
- In the drawer that appears on the right, expand the section
- Use the Who should have access to this Virtual Cluster? field to select all Users/Teams who should get access to this virtual cluster
OPTIONAL: To change the access of any of the selected users or team to this virtual cluster, expand the vcluster Admin role to another appropriate role for each user or team if needed
section and use the selectors to change the- On the very bottom, click on the button to save the changes
To give someone access to a virtual cluster using Loft CLI, run:
loft share vcluster [optional:name]
Configuration
Virtual Cluster Template
metadata.annotations["loft.sh/virtual-cluster-template"] (type: string)
Metadata
Name
metadata.name (type: string)
Namespace
metadata.namespace (type: string)
Labels
metadata.labels (type: map[string]string)
Annotations
metadata.annotations (type: map[string]string)
Advanced Options
Version
spec.helmRelease.chart.version (type: string)
Helm Values
spec.helmRelease.values (type: {})
Apps
Namespaces For Apps
Access To Virtual Cluster
spec.access (type: Access[])