2 minute read  

Connect kubectl

In Kubernetes, the configuration for access to your cluster is a format known as kubeconfig that is normally stored as a file. It contains details such as cluster API server addresses and user access credentials. Treat it as sensitive data. Tools like kubectl use kubeconfig to connect and authenticate to a cluster and perform operations on it. Learn more about kubeconfig and kubectl on kubernetes.io.


  • You are logged on to the Gardener Dashboard.
  • You have created a cluster and its status is operational.

On this page:

Downloading kubeconfig for a cluster

  1. Select your project from the dropdown on the left, then choose CLUSTERS and locate your cluster in the list. Choose the key icon to bring up a dialog with the access options.

    In the Kubeconfig section the options are to download, copy or view the kubeconfig for the cluster. The same options are available also in the Access section in the cluster details screen. To find it, choose a cluster from the list.

  2. Choose the download icon to download kubeconfig as file on your local system.

Connecting to the cluster

In the following command, change <path-to-kubeconfig> with the actual path to the file where you stored the kubeconfig downloaded in the previous steps.

$ kubectl --kubeconfig=<path-to-kubeconfig> get namespaces

The command connects to the cluster and list its namespaces.

Exporting KUBECONFIG environment variable

Since many kubectl commands will be used, it’s a good idea to take advantage of every opportunity to shorten the expressions. The kubectl tool has a fallback strategy for looking up a kubeconfig to work with. For example, it looks for the KUBECONFIG environment variable with value that is the path to the kubeconfig file meant to be used. Export the variable:

$ export KUBECONFIG=<path-to-file>

In the previous snippet make sure to change the <path-to-file> with the path to the kubeconfig for the cluster that you want to connect to on your system.

What’s next?