Loading Posts...

How To Install Kubectl On Windows Using PowerShell

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.

install-kubectl.ps1 [folder_location]

Just allow sometime to run few commands, and automatically execute the “kubectl.exe version” command.

install kubectl on Windows install

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.

Read More: Kubernetes Error: Unable To Connect To The Server Tcp I/O Timeout

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

install kubectl on Windows server address

Then, I tried to execute few kubectl commands, and it was throwing few certificate errors

install kubectl on Windows cluster cert error

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.

install kubectl on Windows host record

After this simple edit, I was able to connect to my Kubernetes cluster remotely from my PowerShell. All the commands worked as expected.

install kubectl on Windows commands succeeded

So I think, these steps will find you as helpful, when you want to install kubectl on Windows using PowerShell.

Click to rate this post!
[Total: 8 Average: 4.1]

Aruna Fernando

"Sharing knowledge doesn't put your job at risk - iron sharpen iron" I heard this and it's true.

Get Updates Directly To Your Inbox!

   

Leave a Comment

Loading Posts...