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

Resources created using kubectl

Rancher will discover and show resources created by kubectl. However, these resources might not have all the necessary annotations on discovery. If an operation (for instance, scaling the workload) is done to the resource using the Rancher UI/API, this may trigger recreation of the resources due to the missing annotations. This should only happen the first time an operation is done to the discovered resource.

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.

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

  2. 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.

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

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

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

    1. Click Kubeconfig File.

    2. Copy the contents displayed to your clipboard.

    3. 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:

      kubectl --kubeconfig /custom/path/kube.config get pods
      
  4. 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.