Connect to a managed cluster with kubectl

After adding a cluster to Tanzu Platform management, you can connect to the cluster from kubectl by using the configuration file that Tanzu Platform generates for you.

Before you begin

This procedure assumes that you have a managed cluster and that you have already performed the following tasks:

  • Install the Kubernetes command-line interface (kubectl).
  • Install and log in with the Tanzu CLI. For more information, see the VMware Tanzu CLI Documentation.
  • Log in to Tanzu Platform hub.

Download the Kubernetes configuration file

You can get the kubeconfig file using Tanzu Platform hub.

Tanzu Platform hub
Perform the following steps in Tanzu Platform hub:
  1. In Tanzu Platform hub, select the project in which you want to add a new cluster.
  2. In the left navigation pane, click to expand Infrastructure, and then click Kubernetes Clusters.
  3. On the Kubernetes Clusters page, click the Clusters tab, and then click the cluster you want to access.
  4. On the cluster detail page, in the upper right corner, click Actions, and then choose Access this cluster from the popup menu.
  5. In the resulting dialog, click Download kubeconfig file.
  6. Save the downloaded YAML file in a location that is accessible to kubectl. For example, in ~/.kube/config or in a location specified in the KUBECONFIG environment variable.

Initialize the configuration

To initialize the configuration:

  1. Run a kubectl command to initialize the configuration. For example, the following command retrieves a list of namespaces in your cluster.

    kubectl get namespaces
    
  2. (Optional) Use the --kubeconfig flag to specify the location and name of your downloaded kubeconfig YAML file. The command looks something like this:

    kubectl --kubeconfig=/path/to/kubeconfig-my-provisioned-cluster.yml get namespaces
    
    Note

    The path/file value that you pass to the --kubeconfig flag must be an absolute path.

check-circle-line exclamation-circle-line close-line
Scroll to top icon