Exposing vcluster (ingress etc.)
By default, vcluster is only reachable via port-forwarding in remote clusters. However, this means that you need access to the host cluster, where the vcluster is running, in order to access it. To directly access vcluster without port-forwarding, you can use one of the following methods:
Local Kubernetes Clusters
If you are using a local Kubernetes cluster, such as docker-desktop, rancher-desktop, KinD or minikube, vcluster will automatically connect to it without the need of port-forwarding.
#
LoadBalancer serviceThe easiest way is to use the flag --expose
in vcluster create
to tell vcluster to use a LoadBalancer service:
Thats it, your vcluster is now externally reachable through a LoadBalancer service.
Check the costs first
Even though using a LoadBalancer is the easiest option, if you use a cloud provider it will be costly to create one Loadbalancer per cluster. Check your cloud vendor about the cost of each LoadBalancer. In general using an Ingress is the most cost effective method.
#
Manual LoadBalancer service creationInstead of using the built-in flag --expose
, you can also create the following load-balancer.yaml
for a vcluster called my-vcluster
in the namespace my-vcluster
yourself:
Create the resource in the namespace via:
Find out the external ip via kubectl get svc vcluster-loadbalancer -n my-vcluster
:
Now create a values.yaml
to create the vcluster with:
Create the virtual cluster with:
Update the current kube config via:
Access the vcluster:
#
NodePort serviceYou can also expose the vcluster via a NodePort service. Create the following nodeport.yaml
for a vcluster called my-vcluster
in the namespace my-vcluster
:
Create the resource in the namespace via:
Find out the external port via kubectl get svc vcluster-nodeport -n my-vcluster
:
Find out the node ips via kubectl get nodes -o wide
:
Now create a values.yaml
to create the vcluster with:
Create the virtual cluster with:
Retrieve the kube config via:
Access the vcluster:
#
IngressAn Ingress Controller with SSL passthrough support will provide the best user experience, but there is a workaround if this feature is not natively supported.
Make sure your ingress controller is installed and healthy on the cluster that will host your virtual clusters. Create the following ingress.yaml
for a vcluster called my-vcluster
in the namespace my-vcluster
:
Create the resource in the namespace via:
Enable SSL Passthrough Feature
If you are using the ingress nginx controller, please make sure you have enabled the SSL passthrough feature as it is disabled by default.
SSL Passthrough required
In order for this ingress to work correctly, you will need to enable SSL passthrough as TLS termination has to happen at the vcluster level and not ingress controller level. If you cannot do that, please take a look below for using an ingress without ssl passthrough.
Now create a values.yaml
to create the vcluster with:
Create the virtual cluster with:
Retrieve the kube config via:
Access the vcluster:
#
Ingress without SSL-PassthroughIf you cannot configure your ingress controller to use ssl-passthrough, you can also create an ingress similar to this:
With this configuration you will need to use service account authentication in order to connect as the ingress controller won't be able to resolve the client-cert and client-key which is used by default as authentication method. To create a kube config that uses a service account, please run the following command:
Then access the vcluster:
#
In-ClusterIn order to access the virtual cluster from within the host cluster, you can directly connect to the vcluster service. Make sure you can access that service and then create a kube config in the following form:
Now access the virtual cluster with: