vCluster

repository·main·Indexed 11 days ago

https://github.com/loft-sh/vcluster

A tool for creating virtualized, highly isolated Kubernetes environments (Tenant Clusters) that run on top of existing clusters or standalone on bare metal. vCluster provides dedicated control planes, cost-efficient multi-tenancy, and support for AI/ML workloads via Private Nodes, including DRA support, gang scheduling, and GPU custom metrics. It is compatible with Kubernetes v1.18+ and can be installed via Helm.

Tokens
63.5K
Snippets
232
Records
287
Agent score
94%

What's inside vCluster

  1. Key features of vCluster

    main

    vCluster provides virtual Kubernetes clusters with several core capabilities:

    • Isolated Virtual Control Plane: Each Tenant Cluster has its own API server, controller manager, and data store, ensuring complete Kubernetes API isolation.
    • Strong Tenant Isolation: Tenants receive admin access within their Tenant Cluster while maintaining minimal permissions on the host Control Plane Cluster.
    • Resource Syncing: Supports bidirectional synchronization of Kubernetes resources (pods, services, secrets, configmaps, CRDs, etc.) between the Tenant Cluster and the Control Plane.
    • Sleep Mode: Allows pausing inactive Tenant Clusters to conserve resources, with instant wake-up capabilities.
    • High Availability: Supports multiple replicas with leader election and can use embedded etcd or external databases like PostgreSQL, MySQL, or RDS.
    • Standalone Deployment: Can be run without a Control Plane Cluster on dedicated infrastructure or bare metal.
    • Integrations: Native support for cert-manager, external-secrets, KubeVirt, Istio, and metrics-server.

    Note on Deployment Modes:

    • Shared / Dedicated Nodes: These modes leverage the Control Plane Cluster's CNI, CSI, ingress, and other infrastructure. Resource syncing and host-cluster integrations apply here.
    • Private Nodes / Standalone: These modes bring their own CNI, CSI, and platform components.
  2. What is vCluster and Tenant Clusters?

    main

    vCluster creates Tenant Clusters, which are fully isolated Kubernetes environments. These environments run on top of a host 'Control Plane Cluster' or can run in 'Standalone' mode on dedicated infrastructure or bare metal.

    Each Tenant Cluster provides its own:

    • API server
    • Custom Resource Definitions (CRDs)
    • Role-Based Access Control (RBAC)

    This allows for a Kubernetes experience that is indistinguishable from a dedicated cluster, providing strict isolation and hardware-aware scheduling while preventing tenant sprawl.

  3. What is a virtual Kubernetes cluster?

    main

    A vcluster is a fully functional virtual Kubernetes cluster that runs inside a namespace of an underlying (host) Kubernetes cluster.

    Key Benefits:

    • Cluster Scoped Resources: Unlike standard namespaces, vclusters allow users to manage CRDs, namespaces, and cluster roles.
    • Cost Efficiency: They are significantly cheaper than full-blown clusters because they run as pods and share the host cluster's resources.
    • Strict Isolation: Each vcluster has its own separate Kubernetes control plane and access point.
    • Cluster Wide Permissions: Users can install applications requiring cluster-wide permissions while being restricted to a single namespace on the host cluster.
    • Testing: Enables testing different Kubernetes versions within a single host cluster.
  4. The vCluster Platform ecosystem

    main

    vCluster is part of a broader platform designed for running production Kubernetes and AI infrastructure. The ecosystem includes:

    • vCluster: Provides Tenant Clusters (Virtual Control Planes) with API, data, and optional network isolation.
    • vNode: Provides runtime-level isolation using kernel-enforced boundaries (seccomp, cgroups, namespaces, AppArmor) without VM overhead.
    • vMetal: Provides zero-touch bare metal provisioning for GPU fleets.
    • Netris (Integration): Provides hardware-enforced network isolation via programmatic VLANs, VRFs, and ACLs.
  5. Compare vCluster Deployment Architectures

    main

    vCluster supports four primary architectures, offering different levels of isolation and infrastructure requirements:

    ArchitectureControl Plane ClusterNode IsolationCNI/CSI IsolationBest For
    Shared NodesRequiredDev/test, high density
    Dedicated NodesRequiredProduction tenants
    Private NodesRequiredCompliance, GPU workloads
    StandaloneNot RequiredAI factories, edge

    Configuration Examples

    Shared Nodes

    Tenant Clusters share the Control Plane Cluster's nodes. Workloads run as regular pods in a namespace.

    sync:
      fromHost:
        nodes:
          enabled: false  # Uses pseudo nodes

    Dedicated Nodes

    Tenant Clusters get their own set of labeled nodes on the Control Plane Cluster.

    sync:
      fromHost:
        nodes:
          enabled: true
          selector:
            labels:
              tenant: my-tenant

    Private Nodes (v0.27+)

    External nodes join the Tenant Cluster directly with their own CNI, CSI, and networking stack.

    privateNodes:
      enabled: true
    controlPlane:
      service:
        spec:
          type: NodePort

    vCluster Standalone (v0.29+)

    Run vCluster without any Control Plane Cluster. The Virtual Control Plane is deployed directly on bare metal or VMs.

    controlPlane:
      standalone:
        enabled: true
        joinNode:
          enabled: true
    privateNodes:
      enabled: true

    Auto Nodes (v0.28+)

    Automatically provision and deprovision private nodes based on workload demand using providers like Karpenter.

    autoNodes:
      enabled: true
      nodeProvider: <provider>
    privateNodes:
      enabled: true
  6. How vCluster e2e tests are structured

    main

    The test suite is organized into two distinct layers to allow for flexible testing across different vCluster configurations:

    1. Spec functions (test_*/): These are self-describing logic blocks. They contain Describe text and feature labels (e.g., labels.Core, labels.Pods) but do not bind to a specific cluster. This allows the same spec to be reused across multiple suites.
    2. Suite files (suite_*_test.go): These files define a specific vCluster configuration. A suite owns:
      • An embedded vcluster-*.yaml template.
      • The vCluster name.
      • The vCluster lifecycle (using Ordered Ginkgo suites and BeforeAll to provision the cluster).
      • Scheduling labels (e.g., labels.PR for gating, or a primary label like labels.Rootless).

    The Lifecycle Helper: Suites use setup/lazyvcluster (a wrapper around vcluster.Create) to provision clusters. This ensures that vClusters are created lazily in the suite's BeforeAll and destroyed in AfterAll. If a spec fails, the framework keeps the vCluster alive and attaches diagnostics (rendered config, pods, events, syncer logs) to the report.

  7. Run vCluster Conformance Tests on GKE

    main

    To run conformance tests, it is recommended to use a GKE host cluster with at least 2 nodes. The process involves three main stages: setting up a GKE cluster with specific firewall rules, creating a vCluster with a custom values.yaml configuration, and executing tests using Sonobuoy.

    Prerequisites

  8. Run vCluster Conformance Tests for Kubernetes v1.21

    main

    To verify vCluster conformance against Kubernetes v1.21, you must set up a host cluster (GKE is recommended), deploy a specifically configured vCluster, and execute tests using Sonobuoy.

    Prerequisites

    Step 1: Prepare the Host Cluster (GKE)

    Create a GKE cluster and ensure a firewall rule is in place to allow incoming connections or NodePort traffic, otherwise tests will fail.

    Step 2: Deploy the vCluster

    You must use a custom values.yaml to configure the vCluster for conformance testing. This configuration uses a specific k3s image, applies broad tolerations to handle node tainting during tests, and configures the syncer to sync nodes and priority classes while disabling ingress sync.

    Step 3: Execute Sonobuoy Tests

    Run the sonobuoy run command in certified-conformance mode using the specified conformance and image versions.

    ### 1. Create GKE cluster
    export PROJECT_NAME=my-google-cloud-project
    export CLUSTER_NAME=conformance-test
    export CLUSTER_ZONE=europe-west3-a
    export CLUSTER_VERSION=1.21.5-gke.1302
    export CLUSTER_CHANNEL=regular
    
    gcloud beta container --project $PROJECT_NAME clusters create $CLUSTER_NAME \
       --zone $CLUSTER_ZONE --no-enable-basic-auth --cluster-version $CLUSTER_VERSION \
       --release-channel $CLUSTER_CHANNEL --enable-ip-alias --no-enable-master-authorized-networks \
       --addons GcePersistentDiskCsiDriver --node-locations $CLUSTER_ZONE
       
    gcloud compute firewall-rules --project $PROJECT_NAME create conformance-firewall-rules --direction=INGRESS --network=default --action=ALLOW --rules=tcp --source-ranges=0.0.0.0/0 --description="vcluster conformance test firewall rule"
    
    ### 2. Create the vcluster
    # values.yaml content:
    # vcluster:
    #   image: rancher/k3s:v1.21.5-k3s1
    # tolerations:
    # - operator: "Exists"
    # rbac:
    #   clusterRole:
    #     create: true
    # syncer:
    #   extraArgs:
    #   - --sync-all-nodes
    #   - --sync-node-changes
    #   - --fake-nodes=false
    #   - --fake-kubelets=false
    #   - --enable-priority-classes
    #   - --disable-sync-resources=ingresses
    
    vcluster create vcluster -n vcluster -f values.yaml --expose
    vcluster connect vcluster -n vcluster
    
    ### 3. Run Tests
    export KUBECONFIG=./kubeconfig.yaml
    export CONFORMANCE_VERSION=v1.21.1
    export SONOBUOY_IMAGE_VERSION=v0.52.0
    export SONOBUOY_LOGS_IMAGE_VERSION=v0.3
    
    sonobuoy run \
      --mode=certified-conformance \
      --kube-conformance-image-version=$CONFORMANCE_VERSION \
      --sonobuoy-image=sonobuoy/sonobuoy:$SONOBUOY_IMAGE_VERSION \
      --systemd-logs-image=sonobuoy/systemd-logs:$SONOBUOY_LOGS_IMAGE_VERSION \
      --wait
  9. Run vCluster end-to-end tests

    main

    The vCluster e2e test suite uses Ginkgo v2 and the e2e-framework. You can manage the test lifecycle using just commands.

    Full cycle (setup, run, and teardown):

    just dev-e2e

    Setup environment only:

    just setup

    Run tests (requires environment to be set up): Use just run-e2e '<filter>' to execute tests. Filters can be suite names, labels, or boolean expressions.

    • All PR-gating tests (excluding non-default): just run-e2e 'pr && !non-default'
    • All tests: just run-e2e ''
    • Specific vCluster suite: just run-e2e 'common-vcluster'
    • By feature label (cross-suite): just run-e2e 'pods'
    • Combined filters: just run-e2e 'pr && pods'
    • Iterate without teardown: just iterate-e2e 'pods'

    Teardown:

    just teardown
  10. Execute conformance tests using Sonobuoy

    main

    Once the vCluster is running and connected, use sonobuoy in certified-conformance mode to run the tests. You must provide the KUBECONFIG pointing to your vCluster and specify the appropriate image versions for conformance and sonobuoy.

    export KUBECONFIG=./kubeconfig.yaml
    export CONFORMANCE_VERSION=v1.19.10
    export SONOBUOY_IMAGE_VERSION=v0.52.0
    export SONOBUOY_LOGS_IMAGE_VERSION=v0.3
    
    sonobuoy run \
      --mode=certified-conformance \
      --kube-conformance-image-version=$CONFORMANCE_VERSION \
      --sonobuoy-image=sonobuoy/sonobuoy:$SONOBUOY_IMAGE_VERSION \
      --systemd-logs-image=sonobuoy/systemd-logs:$SONOBUOY_LOGS_IMAGE_VERSION \
      --wait
  11. Run Kubernetes conformance tests using Sonobuoy

    main

    Once the vcluster is running and connected, you can execute conformance tests using Sonobuoy.

    Ensure you have exported the KUBECONFIG pointing to your vcluster configuration and set the appropriate Sonobuoy image versions before running the sonobuoy run command in certified-conformance mode.

    export KUBECONFIG=./kubeconfig.yaml
    export SONOBUOY_IMAGE_VERSION=v0.55.1
    export SONOBUOY_LOGS_IMAGE_VERSION=v0.4
    
    sonobuoy run \
      --mode=certified-conformance \
      --kubernetes-version=v1.22.5 \
      --sonobuoy-image=sonobuoy/sonobuoy:$SONOBUOY_IMAGE_VERSION \
      --systemd-logs-image=sonobuoy/systemd-logs:$SONOBUOY_LOGS_IMAGE_VERSION \
      --wait