Skip to main content

Deploy in High Availability

By default, vCluster runs one instance of each of its components. That’s fine for many use cases, like ones that are very ephemeral (dev environments, CI/CD, etc.). But suppose your situation requires virtual clusters with more redundancy. In that case, you can use vCluster’s High Availability feature to run multiple copies of the vCluster components so that the cluster is more resistant to partial failures.

Create the HA virtual cluster

To create a virtual cluster using the vcluster CLI, we run the vcluster create command. To enable HA, we’ll need to specify the distro and the values.yaml file to use:

controlPlane:
# Use an external etcd for vCluster
backingStore:
etcd:
deploy:
enabled: true
statefulSet:
highAvailability:
replicas: 3
# Deploy vCluster with 3 replicas
statefulSet:
highAvailability:
replicas: 3
vcluster create ha-tutorial --connect=false -f values.yaml

We’ve named the virtual cluster ha-tutorial. By default, the vcluster create command connects to the virtual cluster, but for the purposes of this tutorial, we’ve disabled that with the --connect=false flag. And we’ve specified the distro and the values.yaml file to use when creating the virtual cluster.

You should see output like this:

info   Creating namespace vcluster-ha-tutorial
...
- Use 'vcluster connect ha-tutorial --namespace vcluster-ha-tutorial' to access the virtual cluster

Some of your output may differ depending on whether you use a local or remote cluster.

As you can see, vcluster has created a namespace called vcluster-ha-tutorial. The virtual cluster lives inside that namespace on the host cluster. Next, let’s see what pods are running in that namespace.

kubectl get pods -n vcluster-ha-tutorial
NAME                                      READY   STATUS    RESTARTS   AGE
ha-tutorial-7c5c5844c5-27j2v 0/1 Running 0 20s
ha-tutorial-7c5c5844c5-gb2sm 0/1 Running 0 20s
ha-tutorial-7c5c5844c5-pwn7k 0/1 Running 0 20s
ha-tutorial-etcd-0 0/1 Running 0 20s
ha-tutorial-etcd-1 0/1 Running 0 20s
ha-tutorial-etcd-2 0/1 Running 0 20s

There are now three replicas of each component of the virtual cluster running. If one API server pod were down, the virtual cluster would continue functioning.

If you’d like more information about how the vcluster pods were scheduled, add the -o wide flag to that previous command.

kubectl get pods -n vcluster-ha-tutorial -o wide

The hostnames of the nodes will be listed in the NODES column.

Connect to the virtual cluster

We can connect to the vcluster using the vcluster connect command.

vcluster connect ha-tutorial
info   Starting proxy container...
done √ Switched active kube context to vcluster_ha-tutorial_vcluster-ha-tutorial_minikube
- Use `vcluster disconnect` to return to your previous kube context
- Use `kubectl get namespaces` to access the vcluster

vcluster connect automatically switches our kube context for kubectl to the virtual cluster. Now we can see the namespaces inside of the virtual cluster by running this command:

kubectl get namespaces
Copy
NAME STATUS AGE
default Active 31s
kube-node-lease Active 33s
kube-public Active 33s
kube-system Active 33s

Our virtual cluster only contains the default namespaces that are created by Kubernetes.

Now let’s disconnect from the virtual cluster.

vcluster disconnect

This will switch your kube context back to the host cluster.

Cleanup

One of the great things about vcluster is that it’s very fast and easy to clean up the virtual clusters when you’re done using them.

vcluster delete ha-tutorial

That will delete the vcluster and the namespace it was in.