TExcelTAD
Home › Platform Engineering: Internal Developer Platforms › Virtual Clusters & Capsule

Virtual Clusters & Capsule

Namespaces stop being enough in two situations: a team needs several namespaces with shared rules (one per app, per preview environment), or a team needs cluster-scoped things (its own CRDs, an operator, cluster-admin for an experiment). Two open-source projects cover these cases without giving everyone a real cluster: Capsule groups namespaces into tenants, and vcluster runs virtual clusters inside a host cluster. Everything in this lesson needs a live cluster, so the files and sessions are samples; check each project's documentation for the version you install.

Capsule: a tenant owns namespaces

Capsule (a CNCF sandbox project) adds a cluster-scoped Tenant resource. Tenant owners can create namespaces themselves (no platform ticket), up to a limit, and Capsule's admission webhooks attach the tenant's quotas, policies and labels to every namespace they create:

yaml
apiVersion: capsule.clastix.io/v1beta2
kind: Tenant
metadata:
  name: growth
spec:
  owners:
    - name: growth-leads           # an identity-provider group
      kind: Group
  namespaceOptions:
    quota: 10                      # at most 10 namespaces
  resourceQuotas:
    scope: Tenant                  # one budget shared by all the tenant's namespaces
    items:
      - hard:
          requests.cpu: "8"
          requests.memory: 16Gi
bash
$ kubectl create namespace growth-preview-pr-142 --as alan --as-group growth-leads   # sample output
namespace/growth-preview-pr-142 created
$ kubectl get tenants
NAME     STATE    NAMESPACE QUOTA   NAMESPACE COUNT   NODE SELECTOR   AGE
growth   Active   10                4                                 41d

Recent Capsule releases also add ResourcePools and mark the Tenant's resourceQuotas for deprecation; check the Capsule docs for the version you install.

Compared with the tenant kit, Capsule moves namespace creation from the platform's Git repository to the tenant, with guardrails enforced at admission time. A good fit for preview environments per pull request.

vcluster: a cluster inside a namespace

vcluster (by vCluster Labs, formerly Loft Labs; open source) runs a Kubernetes control plane (API server, controller manager, a data store) as Pods in a namespace of the host cluster. Tenants get a kubeconfig for the virtual cluster and can do anything there: create namespaces, install CRDs, be cluster-admin. A component called the syncer copies the low-level objects that need real resources (Pods, Services, PersistentVolumeClaims, optionally Ingresses) down to the host namespace, where the host's scheduler runs them on shared nodes.

bash
$ vcluster create growth-dev --namespace vc-growth-dev -f vcluster.yaml      # sample output, abridged
info   Creating namespace vc-growth-dev
info   Create vcluster growth-dev...
done   Successfully created virtual cluster growth-dev in namespace vc-growth-dev
$ vcluster connect growth-dev --namespace vc-growth-dev
done   Switched active kube context to vcluster_growth-dev_vc-growth-dev_...
$ kubectl get namespaces                                                       # inside the virtual cluster
NAME              STATUS   AGE
default           Active   40s
kube-node-lease   Active   40s
kube-public       Active   40s
kube-system       Active   40s

Configuration lives in a vcluster.yaml values file; the platform team sets the host-side guardrails there so a virtual cluster can't escape its share:

yaml
# vcluster.yaml (sample; see vcluster.com/docs for the current schema)
sync:
  toHost:
    ingresses:
      enabled: true
policies:
  resourceQuota:
    enabled: true          # a quota on the host namespace that holds everything the vcluster syncs
  limitRange:
    enabled: true
  networkPolicy:
    enabled: true          # isolate the vcluster's workloads from other host namespaces

How the syncer maps names, modelled

Inside the virtual cluster, a team may create linkly in namespace default and another linkly in staging. On the host, all of them land in one namespace, so the syncer rewrites names to keep them unique and traceable; vcluster's convention is <name>-x-<namespace>-x-<vcluster>, shortened with a hash when it would exceed Kubernetes' limits. A model of that translation:

python · try it yourself
import hashlib

def host_name(name, namespace, vcluster, limit=63):
    full = f"{name}-x-{namespace}-x-{vcluster}"
    if len(full) <= limit:
        return full
    digest = hashlib.sha256(full.encode()).hexdigest()[:10]
    return f"{full[:limit - 11]}-{digest}"

virtual = [("linkly-7d9c-abcde", "default"), ("linkly-7d9c-abcde", "staging"),
           ("postgres-0", "default"), ("a-rather-long-pod-name-from-a-statefulset-0", "integration-tests")]
for name, ns in virtual:
    h = host_name(name, ns, "growth-dev")
    print(f"{ns + '/' + name:62} -> vc-growth-dev/{h} ({len(h)})")
default/linkly-7d9c-abcde                                      -> vc-growth-dev/linkly-7d9c-abcde-x-default-x-growth-dev (40)
staging/linkly-7d9c-abcde                                      -> vc-growth-dev/linkly-7d9c-abcde-x-staging-x-growth-dev (40)
default/postgres-0                                             -> vc-growth-dev/postgres-0-x-default-x-growth-dev (33)
integration-tests/a-rather-long-pod-name-from-a-statefulset-0  -> vc-growth-dev/a-rather-long-pod-name-from-a-statefulset-0-x-integr-6f6dcb83e7 (63)

(The model's hash and truncation are illustrative; the real syncer's details differ by version.) The mapping is why host-side tools still work: the host's metrics, logs and cost tools see real Pods, in the vcluster's host namespace, with names that tell you which virtual namespace they came from. Cost allocation by namespace on the host gives you the cost per virtual cluster for free.

When to use which

Need Use
teams in one company, standard apps namespace per team with the tenant kit
teams create namespaces themselves, e.g. per pull request Capsule (or Hierarchical Namespaces)
teams need CRDs, operators or cluster-admin; ephemeral full clusters for CI vcluster
hostile tenants, compliance boundaries, different Kubernetes versions on different nodes separate clusters

vcluster's control plane costs resources (a small API server and data store per virtual cluster), and its isolation is still soft: workloads share nodes and the kernel. It isolates the API, not the hardware.

Test yourself

What does Capsule's Tenant resource add over plain namespaces?

  1. A separate API server
  2. Tenant owners can create namespaces themselves, and the tenant's quotas and policies are applied to them automatically
  3. Hard kernel isolation
  4. Multi-cluster networking

In vcluster, what runs on the host cluster's nodes?

  1. Nothing
  2. The virtual control plane and the synced low-level objects such as Pods, scheduled by the host
  3. Only the API server
  4. A separate kubelet per tenant

Why does the syncer rename objects when copying them to the host?

  1. For security
  2. Objects from different virtual namespaces land in one host namespace, so names must stay unique and traceable
  3. Kubernetes requires lowercase
  4. To hide them