KOP Recipes - Virtual Clusters (vcluster) - Rafay Product Documentation

Vclusters

Overview

Virtual Clusters are fully working Kubernetes clusters that run on top of other Kubernetes clusters. Compared to fully separate "real" clusters, virtual clusters reuse worker nodes and networking of the host cluster. They have their own control plane and schedule all workloads into a single namespace of the host cluster. Like virtual machines, virtual clusters partition a single physical cluster into multiple separate ones.

As part of the development process, engineers often still need access to cluster-scoped resources like cluster roles, shared CRDs or persistent volumes. Virtual clusters can be configured independently of the physical cluster, this makes them ideal for engineering teams to run experiments, continuous integration and set up sandbox environments.


What Will You Do

In this exercise,

Important
This tutorial describes the steps to create a virtual cluster using the Web Console. The entire workflow can also be fully automated and embedded into an automation pipeline


Assumptions


Enforcing Governance

There are two primary ways to enforce governance, especially in shared cluster environments today:

More information on the "workspace as a service" capability is available here


Step 1: Assign Workspace admin role to user

Step 2: Create the host namespace for the vcluster

Step 3: Create a vcluster

Step 4: Verify deployment

The vcluster-dev-test-0 pod is vcluster with the k3s control-plane and the coredns-586cbcd49f-bn7mz-x-kube-system-x-vcluster-dev-test pod is the coredns deployment for inside the virtual cluster.


Step 5: Secure kubectl access to the vcluster

The platform's Zero Trust Kubectl Access ( ZTKA) capability provides a secure way to perform kubectl operations on clusters deployed in public cloud or on-premise environments.

To access the vcluster, we will perform a kubectl exec to the container running the vcluster. This can be done either via UI or Terminal.

For UI based option:

For Terminal based option:

kubectl config --kubeconfig=kubeconfig-demos@rafay.co set-context <context name>
kubectl exec -it -n <namespace> <pod name> -c vcluster -- /bin/sh

A virtual cluster behaves the same way as a regular Kubernetes cluster.

Let's create a namespace and a demo nginx deployment. You can check that this demo deployment will create pods inside the vcluster.

Here are some key things to notice about this deployment:

Note that you would need to run the commands below with a user who has cluster-wide privileges.

You will notice that the pod that has been scheduled for our nginx-deployment has made it to the underlying host cluster. The reason for this is that vclusters do not have separate nodes. Instead, they have a syncer which synchronizes resources from the vcluster to the underlying host namespace to actually get the pods of the vcluster running on the host cluster's nodes and the containers started inside the underlying host namespace.


Recap

Congratulations! You have successfully created a virtual cluster (vcluster) and securely performed kubectl operations on a remote cluster.