Kubectl installation on Windows

I found it easier to keep executable files that are not managed by Windows itself in a custom folders at “C:\Program Files (Folder)”. Executables are placed under their individual folder, path to which gets added to the Windows machine’s Path variable.

Find the latest version of kubectl from here. CD into the folder where you would like to store the kubectl executable. Keep in mind, this folder will be added to Windows machine’s path variable. In the current example this will be at “C:\Program Files (Folder)\Kubernetes”. Follow the commands below to create the folder and download kubectl.

c:\
c:\mkdir "Program Files (Folder)"
c:\cd "Program Files (Folder)"
c:\Program Files (Folder)\mkdir Kubernetes
c:\Program Files (Folder)\cd Kubernetes
c:\Program Files (Folder)\Kubernetes\

Once in the folder use the command below to download the desired version of kubectl. Replace {VERSION} with the desired version.

curl -LO "https://dl.k8s.io/release/{VERSION}/bin/windows/amd64/kubectl.exe"

Also download the checksum file using the command below.

curl -LO "https://dl.k8s.io/{VERSION}/bin/windows/amd64/kubectl.exe.sha256"

validate the executable against the checksum.

Manually:

c:\Program Files (Folder)\Kubernetes\CertUtil -hashfile kubectl.exe SHA256
c:\Program Files (Folder)\Kubernetes\type kubectl.exe.sha256

Using powershell:

$($(CertUtil -hashfile .\kubectl.exe SHA256)[1] -replace " ", "") -eq $(type .\kubectl.exe.sha256)

Once verified add the kubectl folder path to the machine’s Path variable using the command below. This requires elevated privileges.

[Environment]::SetEnvironmentVariable("Path", "$($env:path);c:\Program Files (Folder)\Kubernetes", [System.EnvironmentVariableTarget]::Machine)

Reload the Path environment variable.

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")

At this point you should be able to use kubectl to manage your kubernetes cluster. Make sure your user profile folder has a .kube directory and a valid kubernetes cluster config file inside it.

Leave a Reply

Your email address will not be published. Required fields are marked *