Skip to main content

Get a kubeconfig file for your virtual cluster

To connect to a virtual cluster's Kubernetes API server, you can either manually create a kubeconfig file or use the vCluster CLI to generate and update it automatically.

Retrieve using the vCluster CLI​

The easiest way to retrieve a kubeconfig for your virtual cluster is by using the vCluster CLI.

You can update your current kubeconfig on your local machine by running the following command:

vcluster platform connect my-vcluster

If you want to print the kubeconfig file, you can append --print to the command:

vcluster platform connect my-vcluster --print
info

If you have multiple virtual clusters with the same name, a sub-menu will be presented that allows you to specify the vcluster by project.

info

If you have direct cluster endpoints or ingress endpoints for virtual clusters enabled, the resulting kubeconfig will look different.

Create kubeconfig without the CLI​

You can also create a kubeconfig manually by creating an access key for your user first and then using the following template, with the following placeholders:

  • $PROJECT: the project the virtual cluster is in
  • $VIRTUAL_CLUSTER: the virtual cluster name to connect to
  • $LOFT_HOST: the loft host you connect to
  • $ACCESS_KEY: the access key to use

Then replace the placeholders in the following template and save the configuration as my-kubeconfig.yaml:

apiVersion: v1
kind: Config
clusters:
- cluster:
server: https://$LOFT_URL/kubernetes/project/$PROJECT/virtualcluster/$VIRTUAL_CLUSTER
# Optional: if the server uses an insecure certificate
# insecure-skip-tls-verify: true
name: loft
contexts:
- context:
cluster: loft
user: loft
name: loft
current-context: loft
users:
- name: loft
user:
token: $ACCESS_KEY

You can access your virtual cluster by using the freshly created kubeconfig file:

KUBECONFIG=my-kubeconfig.yaml kubectl get namespaces