Using kubectl to Access a Cluster


You can access and manage your Kubernetes clusters using kubectl in two ways:

Accessing Clusters with kubectl Shell

You can access and manage your clusters by logging into Rancher and opening the kubectl shell. No further configuration necessary.

  • From the Global view, open the cluster that you want to access with kubectl.

  • Click Launch kubectl. Use the window that opens to interact with your Kubernetes cluster.

For more information on using kubectl, see Kubernetes Documentation: Overview of kubectl.

Accessing Clusters with kubectl and a kubeconfig File

Alternatively, you can access your clusters by installing kubectl on your workstation, and then directing it toward a kubeconfig file automatically generated by Rancher. After install and configuration, you can access your clusters without logging into Rancher.

  • Install kubectl on your workstation. For more information, see Kubernetes Documentation: Install and Set Up kubectl.

  • Log into Rancher. From the Global view, open the cluster that you want to access with kubectl.

  • Copy the cluster’s kubeconfig file to your workstation.

    • Click Kubeconfig File.

    • Copy the contents displayed to your clipboard.

    • Paste the contents into a new file on your local computer. Move the file to ~/.kube/config.

Note: The default location that kubectl uses for the kubeconfig file is ~/.kube/config, but you can use any directory and specify it using the —kubeconfig flag, as in the sample that follows:

  1. kubectl kubeconfig /custom/path/kube.config get pods
  • From your workstation, launch kubectl. Use it to interact with your kubernetes cluster.

For more information on using kubectl, see Kubernetes Documentation: Overview of kubectl.