Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install kubectl on ubuntu (WSL) and use kubectl config from Windows
# Receives your Windows username as only parameter.
curl -LO
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
mkdir -p ~/.kube
ln -sf "/mnt/c/users/$windowsUser/.kube/config" ~/.kube/config
kubectl version
Copy link

Sonata165 commented Jul 22, 2020

cool and useful

Copy link

orinwalker commented Nov 3, 2021

Fantastic. Works perfectly. Thank you!

Copy link

jmicans commented Dec 3, 2021


Copy link

Mustafa017 commented Dec 28, 2021

Nice solution. Thanks

Copy link

aLucaz commented Jan 16, 2022


Copy link

xak2000 commented Jan 26, 2022

An alternative solution (Verified with Docker Desktop for Windows with WSL2)

Start WSL2 session (e.g. Ubuntu) and add into ~/.profile:

export KUBECONFIG=/mnt/c/users/$USER/.kube/config

Close and reopen WSL2 session to make bash re-read .profle file.

This makes kubectl executed in WSL2 to directly use kubectl config file from Windows host. No symlink required.

Copy link

S-Effendi commented Mar 15, 2022

Instead of having to re-open your WSL2 windows shell you could simply reload your shell with: source ~/.profile

Copy link

sivabalan19 commented Jun 29, 2022

@xak2000 @S-Effendi @cmendible , How are you guys tricking the windows location of client-certificate & client-key in the config file.

Copy link

Scared-Heart commented Aug 8, 2022

nice work, thx~

Copy link

msvirtualguy commented Aug 25, 2022

This is great, very helpful! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment