Skip to content

Instantly share code, notes, and snippets.

@cmendible
Created November 16, 2019 22:02
Show Gist options
  • Star 60 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save cmendible/ee6119ee202becd743888435e830b987 to your computer and use it in GitHub Desktop.
Save cmendible/ee6119ee202becd743888435e830b987 to your computer and use it in GitHub Desktop.
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
@tc-sriram1998
Copy link

My .kube/config file is empty

@andyted
Copy link

andyted commented Mar 13, 2023

create an alias in WSL to reference the kubectl.exe in Windows

alias kubectl=/mnt/c/kubectl.exe

@iverson-yang
Copy link

@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

@Marcos-br
Copy link

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

@agosalvez
Copy link

Thanks! cool!

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