In this post, let’s see the complete steps to Install Kubectl on Windows to manage your Kubernetes cluster remotely. It was quite an easy install, but I have noticed a few things when I was installing the kubectl. I thought it was better to share my experience in this post.
There are many ways to setup kubectl in various Operating Systems, this is one of the methods, which you can use to install on Microsoft Windows using PowerShell Gallery. You can find all the steps in Kubernetes official website.
Simply just execute the below command in your PowerShell prompt, I have created a folder, and I’m gonna install the necessary files into that folder
Install-Script -Name install-kubectl -Scope CurrentUser -Force
After that execute the below command specifying the created folder location.
Just allow sometime to run few commands, and automatically execute the “kubectl.exe version” command.
In my instance, as I specified the folder my kubectl.exe file will be located in the created folder, which is “C:\kubectl“. My “config” file located is located in my user account folder.
I have noticed the below error message due to a connection issue to the “kube master” node.
Unable to connect to the server: dial tcp [: :]:8080: connectex: No connection could be made because the target machine actively refused it.
That was due to the misconfiguration of the “config” file, actually I haven’t configured it yet.
So I have copied my config file, which was located in “~/.kube/config” from my Kube Master to the location specified in the above screen capture.
If you open up the “config” file you might notice the server address as below
Then, I tried to execute few kubectl commands, and it was throwing few certificate errors
I used, the simple installation, as I explained in my previous article with flannel networking so certificates generated automatically. I was trying to connect from remotely, and this FQDN doesn’t match to my public accessible url.
Simply, I added a record to the local host file to resolve the DNS to the public IP address, which is publicly accessible.
After this simple edit, I was able to connect to my Kubernetes cluster remotely from my PowerShell. All the commands worked as expected.
So I think, these steps will find you as helpful, when you want to install kubectl on Windows using PowerShell.