Deploy in High Availability
By default, vCluster runs one instance of each of its components. This deployment method is recommended for any uses cases that are very ephemeral (e.g. dev environments, CI/CD, etc.), but for most production use cases, you will want to run vCluster with more redundancy. We recommend deploying vCluster in High Availability (HA) mode to run multiple copies of the vCluster components so that the virtual cluster is more resistant to partial failures.
Create the HA virtual cluster
To create a vCluster using the vCluster CLI, we run the vcluster create
command. To enable HA, we’ll need to specify the distro and the vcluster.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 vcluster.yaml
We’ve named the vCluster ha-tutorial
. By default, the vcluster create
command connects to the vCluster after creation,
but for the purposes of this tutorial, we’ve disabled this automatic connection by adding in the --connect=false
flag.
You should see output like this:
info Creating namespace vcluster-ha-tutorial
...
- Use 'vcluster connect ha-tutorial --namespace vcluster-ha-tutorial' to access the vCluster
Some of your output may differ depending on whether you use a local or remote cluster.
As you can see, the creation of a vCluster has created a namespace called vcluster-ha-tutorial
in the host cluster, and the components of the vCluster lives inside this namespace. 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 vCluster running. If one API server pod went down, the vCluster would continue functioning.
If you’d like more information about how the pods were scheduled in the vCluster, add the -o wide
flag to the kubectl get pods
command:
kubectl get pods -n vcluster-ha-tutorial -o wide
The hostnames of the nodes will be listed in the NODES column.
Connect to vCluster
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 vCluster. Now, we can list the namespaces inside of the vCluster 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 vCluster only contains the default namespaces that were created by Kubernetes.
Now let’s disconnect from the vCluster.
vcluster disconnect
This will switch your kube context back to the host cluster.
Cleanup
One of the great things about running vCluster is that it’s very fast and easy to clean up all the components of the vCluster when you’re done using them.
vcluster delete ha-tutorial
That will delete all components of the vCluster and the namespace it was in.