kubernetes - "kubectl" installation fails on Windows from PowerShell

2/2/2021

Installation on windows should be very simple from the docs https://kubernetes.io/docs/tasks/tools/install-kubectl but mine fails at second step

Install-Script -Name 'install-kubectl' -Scope CurrentUser -Force
install-kubectl.ps1 [-DownloadLocation <path>]


install-kubectl.ps1 c:\kubectl
==>Getting download link from  https://kubernetes.io/docs/tasks/tools/install-kubectl/
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At C:\Program Files\PowerShell\Scripts\install-kubectl.ps1:31 char:8
+ $req = Invoke-WebRequest -UseBasicParsing -Uri $uri
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

It seems like it is trying to download something from https://kubernetes.io/docs/tasks/tools/install-kubectl/ but it can not.

I succeeded to check that connection, I do have access to internet from that Windows Server:

PS C:\Users\e561> Test-NetConnection -ComputerName "kubernetes.io" -Port 443


ComputerName     : kubernetes.io
RemoteAddress    : 147.75.40.148
RemotePort       : 443
InterfaceAlias   : Ethernet 2
SourceAddress    : 10.7.147.211
TcpTestSucceeded : True
-- AndreyS
kubectl
kubernetes

1 Answer

2/3/2021

As mentioned in the comments :

You can download kubectl.exe from here - and later add the path kubectl.exe located to environment variables.

-- Amit Baranes
Source: StackOverflow