DEV Community

Lukas Gentele
Lukas Gentele

Posted on • Originally published at loft.sh

How to Assign vCluster to Specific Nodes Using Node Selectors

When deploying a vCluster, you might need to ensure it runs on specific nodes, such as GPU-enabled nodes or production-specific nodes. This can be achieved using node selectors, which limit the scheduling of the vCluster control plane pods to nodes with specific labels.

Example Configuration

To schedule your vCluster control plane on nodes labeled environment=GPU, use the following configuration in your Helm chart:

controlPlane:
  statefulSet:
    scheduling:
      nodeSelector:
        environment: GPU
Enter fullscreen mode Exit fullscreen mode

This ensures that the vCluster control plane only runs on nodes labeled with environment=GPU.

Why Use Node Selectors?

  • Resource Optimization: Assign vCluster workloads to nodes with specific resources (e.g., GPUs).
  • Isolation: Keep vCluster workloads separate from other applications.
  • Environment Control: Deploy to specific environments, such as production or staging.

Let’s see this in Action 

Step 1: Open Killercoda playground

You can go to the Killercoda Kubernetes playground

Step 2: Install the Vcluster  CLI

Command:

curl -L -o vcluster "https://github.com/loft-sh/vcluster/releases/latest/download/vcluster-linux-amd64" && sudo install -c -m 0755 vcluster /usr/local/bin && rm -f vcluster
Enter fullscreen mode Exit fullscreen mode

Step 3: Create the demo.yaml configuration file 

Command:

cat <<EOF > demo.yaml
controlPlane:
  statefulSet:
    scheduling:
      nodeSelector:
        environment: GPU
EOF
Enter fullscreen mode Exit fullscreen mode

Step 4: Label the controlplane node for Killercoda

Let’s Label the node 

Command:

kubectl label node controlplane environment=GPU
Enter fullscreen mode Exit fullscreen mode

Output: 

Step 5: Create vCluster

Command:

vcluster create demo -f demo.yaml 
Enter fullscreen mode Exit fullscreen mode

Output:

Let’s Verify 

Command:

kubectl config use-context kubernetes-admin@kubernetes
kubectl get pods -n vcluster-demo -owide
Enter fullscreen mode Exit fullscreen mode

Output:

As you can see above, the stateful set for the vCluster created landed on the node names controlplane and this was the node where we set up the label. This is how you can assign vCluster to a specific node and if you want to do that for the pods within the vCluster too, you can follow the documentation here.

Top comments (0)