Skip to main content
Version: 2.3

Virtual Clusters in Loft

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.

# 1. Create virtual cluster
loft create vcluster dev-anna
✓ Creating namespace 'vcluster-dev-anna'
✓ Applying security templates to namespace
✓ Starting virtual cluster inside namespace
✓ Virtual cluster 'dev-anna' successfully started.
Loft has created a kube-context on your local machine to access this virtual cluster. It is your current kube-context now.

# 2. Work within virtual cluster
kubectl get namespaces
NAME STATUS AGE
default Active 5s
kube-system Active 5s
kube-public Active 5s
kube-node-lease Active 5s

kubectl create deployment nginx-deployment --image=nginx
deployment.apps/nginx-deployment created

kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-mnvzz 1/1 Running 0 3s

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

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.

Delete Virtual Clusters
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.

List Virtual Clusters

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]

Virtual Cluster Templates

Loft allows you to create templates for virtual clusters. Virtual cluster templates are optional templates that a user can choose to apply when creating a virtual cluster.

Common use cases for virtual cluster templates may be:

  • Adding development tooling to a virtual cluster
  • Deploying pre-populated databases with test data
  • Equipping new virtual clusters with optional credentials, CRDs, etc.
1. Create Virtual Cluster Template
  1. Go to the Virtual Clusters view using the menu on the left
  2. Switch to the Virtual Cluster Templates tab
  3. Click the button to create a new virtual cluster template
  4. In the drawer that appears on the right, use the field Display Name to specify a Name for your virtual cluster template
  5. Specify any of these options: labels, annotations, virtual cluster version, helm values and apps to deployed
  6. Expand the Space Template section to specify which Space Template should be applied for the underlying host namespace if being created as part of the virtual clusters creation process
  7. On the very bottom, click on the button to create this virtual cluster template
2. Create Virtual Cluster Based On Template

To use a virtual cluster template to create a virtual cluster using Loft CLI, run:

loft create vcluster [vcluster-name] --template [template-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.

Sleep Mode

Loft's sleep allows you to configure an inactivity timeout for virtual clusters after which the virtual cluster will be put to sleep automatically. Technically, the sleep mode does not work directly on the virtual cluster itself but rather on the host namespace where the virtual cluster is running inside of.

Learn more about configuring sleep mode for spaces.

Auto-Delete

Loft's auto-delete feature allows you to configure an inactivity timeout for virtual clusters after which the virtual cluster will be deleted automatically. Technically, auto-delete does not work directly on the virtual cluster itself but rather on the host namespace where the virtual cluster is running inside of.

Learn more about configuring auto-delete for spaces.

Access Permissions

Loft makes it easy to give other users or even entire teams access to one of your virtual clusters.

To give someone access to a virtual cluster using Loft CLI, run:

loft share vcluster [optional:name]