Skip to content

Virtual clusters

A virtual cluster, such as one made with vCluster, runs its own API server inside a namespace of a host cluster. For kubelatch it is one more cluster: you register it, the bootstrap goes inside it, and people reach it through the proxy with their own permissions and credentials. This page registers one by hand, in every edition; for a platform that registers many by itself, see Many virtual clusters.

kubelatch is tested with vCluster 0.37.6, with its k8s distro and virtual Kubernetes 1.35. The examples use a vCluster released as vcluster in the host namespace tenant-a1.

Before you start

  • A kubelatch administrator, and the host cluster's kubeconfig in $HOST_KUBECONFIG.
  • Kubernetes 1.30 or later inside the virtual cluster, as for any cluster (Before you start).
  • Each virtual cluster counts as one cluster toward the edition's limit: the Free edition allows 2 (Editions and license).

The address and the certificate

kubelatch reaches the virtual API server at an https address, and the server's certificate names that address's host.

  • kubelatch runs in the host cluster: it reaches the vCluster's Service, https://<release>.<namespace>.svc:443, here https://vcluster.tenant-a1.svc:443. kubelatch's chart restricts only incoming traffic, so this needs nothing else, unless a NetworkPolicy in the vCluster's namespace keeps kubelatch's pods out.
  • kubelatch runs elsewhere: use the address at which the vCluster is exposed, through a LoadBalancer or an Ingress of its own, and that kubelatch's pods reach. Private clusters covers the network.

With vCluster, list that host in controlPlane.proxy.extraSANs, in the values of its Helm release. exportKubeConfig.server puts the same address in the kubeconfig the vCluster exports to the host, which suits a registrar that runs in the host:

controlPlane:
  proxy:
    extraSANs:
      - vcluster.tenant-a1.svc
exportKubeConfig:
  server: https://vcluster.tenant-a1.svc:443

The CA is the virtual cluster's own, the one in its kubeconfig, and the enrollment command sends it.

Register it

  1. Save the virtual cluster's administrator kubeconfig, which vCluster exports to the host in the vc-<release> Secret:

    kubectl --kubeconfig "$HOST_KUBECONFIG" -n tenant-a1 get secret vc-vcluster \
      -o jsonpath='{.data.config}' | base64 -d > vcluster.kubeconfig
    

    That file is an administrator credential of the virtual cluster: delete it when you are done.

  2. To reach the virtual cluster from your machine, keep a port-forward to its Service open in another terminal:

    kubectl --kubeconfig "$HOST_KUBECONFIG" -n tenant-a1 port-forward svc/vcluster 18443:443
    

    Then point the kubeconfig at it, keeping the Service's name for the certificate check:

    kubectl --kubeconfig vcluster.kubeconfig config set-cluster \
      "$(kubectl --kubeconfig vcluster.kubeconfig config view -o jsonpath='{.clusters[0].name}')" \
      --server=https://127.0.0.1:18443 --tls-server-name=vcluster.tenant-a1.svc
    
  3. In Clusters, register the cluster as usual (Register the cluster). In its Enroll card, with OIDC login on, choose With the script. Open Advanced options, type the address in API server URL for kubelatch, https://vcluster.tenant-a1.svc:443, and click Generate command.

  4. Run the Enrollment command with the virtual cluster's kubeconfig:

    (export KUBECONFIG=vcluster.kubeconfig; <enrollment-command>)
    

    The script says where kubelatch will reach the cluster (kubelatch will reach that API server at https://vcluster.tenant-a1.svc:443.), applies the bootstrap manifest inside the virtual cluster and sends kubelatch the tokens with the virtual cluster's CA. kubelatch validates them through that address before storing them.

Do it by hand works too, with the Service's address as the JSON's server in place of the port-forward's. Then check that it works: the cluster says Ready, with the provider Kubernetes.

Inside the virtual cluster

kubelatch works inside as in any other cluster:

  • Permissions, groups, environments and access requests apply to it as to the rest.
  • The virtual API server sees each person as user:<login>, with the groups of their permissions, and a 403 ends with the role that would allow the request (403 — no permission).
  • Audit has one row per request, 403s included (Audit and retention).
  • logs, exec, port-forward and kubectl debug reach the pod through the vCluster's syncer, which runs it in the host. In a baseline namespace, kubectl debug needs --profile=baseline, as on any cluster.
  • The bootstrap's two admission policies, the reconciler's jail and the one that keeps kubelatch's names out of other people's bindings, deny inside the virtual API server (Security model).
  • Revoking a permission cuts it at the next request, and kubelatch watches the virtual cluster's namespaces: a namespace that loses its Pod Security label loses its permissions within seconds (Reconciliation).

developer, debugger, admin and the custom roles that require it need the pod-security.kubernetes.io/enforce label, baseline or restricted, on the namespace inside the virtual cluster (The rules). The virtual cluster's namespaces start without it, and kubelatch refuses those permissions until they have it:

kubectl --kubeconfig vcluster.kubeconfig label namespace default pod-security.kubernetes.io/enforce=baseline

The host and the virtual cluster

The isolation between a virtual cluster and its host is the substrate's: kubelatch neither strengthens nor weakens it. On the host, the vCluster's namespace holds the virtual cluster's administrator credentials, so a permission there that reads Secrets or creates pods, through kubelatch or not, reaches the whole virtual cluster.

Delete a virtual cluster

Remove it from kubelatch when you delete the vCluster (Delete a cluster); the bootstrap goes away with the virtual cluster.

kubelatch never removes a cluster that stops answering, since a network outage looks the same. A vCluster deleted without removing it from kubelatch leaves the cluster Unreachable, and the proxy answers 502 could not talk to the cluster's API server: API server unreachable. Delete it in kubelatch then: the cleanup cannot reach the API server and the final dialog says so, but the cluster goes, with its permissions and the credentials restricted to it, and its audit stays. In Pro, a webhook with A cluster that stops answering tells you after 15 minutes.

Many virtual clusters

A platform that creates a virtual cluster per tenant registers them with a bot instead: Clusters registered by a machine, in Pro. Register the host cluster first, and give the bot's rule an id prefix, .svc as API server host, the environment and labels that bring the permissions on a set, the host as Parent cluster and, for short-lived clusters, a Maximum lifetime. For each vCluster, the operator does what this page does by hand: it reads the exported kubeconfig, applies the bootstrap, sends the tokens with the Service's address and the CA, and calls DELETE from its finalizer. Each virtual cluster then folds under its host in Clusters and, under a Maximum lifetime, expires by itself when nobody renews it (The life of a registered cluster).