-
-
Save cmendible/ee6119ee202becd743888435e830b987 to your computer and use it in GitHub Desktop.
#!/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 |
Fantastic. Works perfectly. Thank you!
Thanks
Nice solution. Thanks
cool
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.
Instead of having to re-open your WSL2 windows shell you could simply reload your shell with: source ~/.profile
@xak2000 @S-Effendi @cmendible , How are you guys tricking the windows location of client-certificate & client-key in the config file.
nice work, thx~
This is great, very helpful! Thanks
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?
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
My .kube/config file is empty
create an alias in WSL to reference the kubectl.exe in Windows
alias kubectl=/mnt/c/kubectl.exe
@sivabalan19 excute below commands after minikube start:
kubectl config set-credentials minikube
--client-certificate=/mnt/c/Users/$USER/.minikube/profiles/minikube/client.crt
--client-key=/mnt/c/Users/$USER/.minikube/profiles/minikube/client.key --embed-certs
kubectl config set-cluster minikube
--certificate-authority=/mnt/c/Users/$USER/.minikube/ca.crt --embed-certs
I enjoyed the script very much. As I searched for the latest version, I completed the task in this manner:
curl https://storage.googleapis.com/kubernetes-release/release/stable.txt > ./stable.txt
export KUBECTL_VERSION=$(cat stable.txt)
curl -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
mkdir -p ~/.kube
ln -sf "/mnt/c/users/$USER/.kube/config" ~/.kube/config
rm ./stable.txt
Thanks! cool!
Thank you :)
If you're using devcontainers, you typically mount the WSL ~/.kube folder into the devcontainer for consistent k8s access, as here. Unfortunately, if the config file is a symlink, this does not work, as docker cannot follow the symlink in the mount. This can be corrected if you symlink the entire ~/.kube folder in WSL, rather than just the config file... Do you see any drawbacks to symlinking the whole folder?
I enjoyed the script very much. As I searched for the latest version, I completed the task in this manner:
curl https://storage.googleapis.com/kubernetes-release/release/stable.txt > ./stable.txt export KUBECTL_VERSION=$(cat stable.txt) curl -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl mkdir -p ~/.kube ln -sf "/mnt/c/users/$USER/.kube/config" ~/.kube/config rm ./stable.txt
thanks to all and thanks @Marcos-br for your commands
Many thanks!! @Marcos-br
cool and useful