Playing with vcluster

Intro

Create fully functional virtual Kubernetes clusters – Each vcluster runs inside a namespace of the underlying k8s cluster. It’s cheaper than creating separate full-blown clusters and it offers better multi-tenancy and isolation than regular namespaces.

A vcluster is a k8s cluster that runs on top of other k8s, and a vcluster consists of a pod with two containers.

  • One is K3S, which is used to provide the K8S API server, Controller Manager to connect to the data store, and the storage can use external etcd, mysql. By default, sqlite is used
  • The other is Syncer, which is used to copy the pods created in the vcluster cluster to the underlying host, which means that the actual workload still runs in the underlying cluster, so there is no performance loss, because all pods communicate with the api server in the vcluster, so it can reduce the apiserver pressure in the host cluster, and it is lightweight enough

Operation

Download CLI first, install it by default, you can also use helm directly, and then use argocd to deploy

curl -L -o vcluster "https://github.com/loft-sh/vcluster/releases/latest/download/vcluster-linux-amd64" && chmod +x vcluster;

sudo mv vcluster /usr/local/bin;

Create a cluster

vcluster create vcluster-1

There will be more clusters after they are created

vcluster-vcluster-1

Such an ns, no matter how many pods you create in the vcluster, will be under this ns

In addition to this ns there is

vcluster-1-0

Such a statefulset contains the two components mentioned above, that is, two containers

In addition, it is such a pod, which is actually started in the vcluster by default

coredns-66ffcc6b58-jrkwp-x-kube-system-x-vcluster-1

Use the following command to connect to the cluster

vcluster connect vcluster-1

root@k3s1:~# vcluster connect vcluster-1
done √ Switched active kube context to vcluster_vcluster-1_vcluster-vcluster-1_default
warn Since you are using port-forwarding to connect, you will need to leave this terminal open

  • Use CTRL+C to return to your previous kube context
  • Use ‘kubectl get namespaces‘ in another terminal to access the vcluster
    Forwarding from 127.0.0.1:11621 -> 8443
    Forwarding from [::1]:11621 -> 8443
    After that, you can deploy the resources

clean

vcluster delete vcluster-1

Conclusion

If you want to create a test environment, this is great, I think it’s easier than kind. And some customer-oriented deployments of some businesses will use this deployment faster, will not affect the customer’s environment, or in other words, when you have production, testing, development, etc., directly pull up a set, which is much simpler than creating a k8s environment

Article Categories:
docker · meocloud · meocoud · tutorial · vps

Leave a Reply

Your email address will not be published. Required fields are marked *

Don't Miss! random posts ..