← Back to Blog

πŸ‹ How to Set Up kubeconfig for Rancher Desktop in WSL πŸš€

πŸ‹ How to Set Up kubeconfig for Rancher Desktop in WSL πŸš€ Here’s how you can set up the kubeconfig in WSL to access Rancher Desktop’s Kubernetes environment: πŸ‹ How to Set Up kubeconfig for Rancher Desktop in WSL πŸš€ Step 1: Locate the kubeconfig File in Windows Open Rancher Desktop a

πŸ‹ How to Set Up kubeconfig for Rancher Desktop in WSL πŸš€

Here’s how you can set up the kubeconfig in WSL to access Rancher Desktop’s Kubernetes environment:


πŸ‹ How to Set Up kubeconfig for Rancher Desktop in WSL πŸš€


Step 1: Locate the kubeconfig File in Windows

  • Open Rancher Desktop and verify that Kubernetes is running.

  • Find the location of your kubeconfig file on Windows. By default, it is located here:

C:\Users\.kube\config

You’ll need to reference this file from within WSL.


Step 2: Access Windows Files from WSL

WSL can access your Windows file system, so you can use the Windows path in WSL to set up the Kubernetes configuration.

  • Open your WSL terminal (Ubuntu or any other distribution you use).

  • In your WSL shell, map the Windows path to where the kubeconfig file is stored. WSL mounts the Windows file system under /mnt/, so the path will look like this:

export KUBECONFIG=/mnt/c/Users//.kube/config

  • Run the command to verify the new KUBECONFIG environment variable is set correctly.

echo $KUBECONFIG


Step 3: Test the Kubernetes Configuration

  • Now, try running a Kubernetes command to ensure the configuration is working. You can check the nodes in your cluster using the following:

kubectl get nodes

If the setup is correct, you should see output like this, indicating your connection to Rancher Desktop’s Kubernetes cluster:

NAME STATUS ROLES AGE VERSION
rancher-desktop Ready master Xm v1.XX.X

  • You can also verify the kubectl context with:

kubectl config get-contexts
kubectl config view

This should show the rancher-desktop context as your current configuration.


Step 4: Make the KUBECONFIG Persistent (Optional)

To ensure that the KUBECONFIG environment variable is available every time you open your WSL terminal, you can add it to your shell’s configuration file:

  • Open your .bashrc or .zshrc file (depending on your shell) in a text editor:

nano ~/.bashrc

  • Add the following line at the end of the file:

export KUBECONFIG=/mnt/c/Users//.kube/config

  • Save and exit the file. Then, source it to apply the changes immediately:

source ~/.bashrc

Now, every time you open your WSL shell, it will automatically use the Rancher Desktop kubeconfig.


πŸŽ‰ You’re All Set!

You’ve successfully configured kubeconfig for Rancher Desktop on WSL. Now, you can use kubectl within WSL to manage and interact with your Kubernetes cluster running on Rancher Desktop in Windows.


Feel free to reach out if you need further assistance or want to dive deeper into Rancher Desktop and Kubernetes!


Imported from rifaterdemsahin.com Β· 2025