Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install kubectl on ubuntu (WSL) and use kubectl config from Windows
#!/bin/bash
# Receives your Windows username as only parameter.
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
windowsUser=$1
mkdir -p ~/.kube
ln -sf "/mnt/c/users/$windowsUser/.kube/config" ~/.kube/config
kubectl version
@orinwalker
Copy link

Fantastic. Works perfectly. Thank you!

@jmicans
Copy link

jmicans commented Dec 3, 2021

Thanks

@Mustafa017
Copy link

Nice solution. Thanks

@aLucaz
Copy link

aLucaz commented Jan 16, 2022

cool

@xak2000
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.

@S-Effendi
Copy link

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

@sivabalan19
Copy link

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

@Scared-Heart
Copy link

nice work, thx~

@msvirtualguy
Copy link

This is great, very helpful! Thanks

@ShivangShandilya
Copy link

i did the above steps but it says:
The connection to the server localhost:8080 was refused - did you specify the right host or port?

@cmendible
Copy link
Author

i did the above steps but it says: The connection to the server localhost:8080 was refused - did you specify the right host or port?

Check your .kube/config

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