Created
November 16, 2019 22:02
-
-
Save cmendible/ee6119ee202becd743888435e830b987 to your computer and use it in GitHub Desktop.
Install kubectl on ubuntu (WSL) and use kubectl config from Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! cool!