Kubernetes Command-Line Tool (kubectl) on Windows

Kubernetes Command Line Tool on Windows
This tutorial explains the steps to install and set up kubectl on Windows systems. 

 

The Kubernetes is an open-source container-orchestration system for automating application deployment, management, and scaling. Kubernetes was initially designed by Google and is now managed and maintained by the Cloud Native Computing Foundation. 

Kubernetes helps to enable the different operations of an elastic web server framework for cloud applications. Kubernetes can support data center outsourcing to public cloud service providers or can be used for web hosting at scale. Users can deploy both website and mobile applications with complex custom code using Kubernetes on commodity hardware to lower the costs of web server provisioning with public cloud hosts and optimize software development processes.

The Kubernetes command-line tool, commonly known as kubectl, allows users to run commands against Kubernetes clusters. Users can use kubectl to deploy applications, manage and inspect cluster resources, and view logs. For configuration, kubectl checks for a file named configuration in the $HOME/.kube directory. Users can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the –kubeconfig flag. 

Users must use a kubectl version that is within one minor version difference of their cluster. For example, a v1.22 client can communicate with v1.23, v1.22, and v1.21 control panels. Using the latest version of kubectl helps to avoid unforeseen issues on the system. In this tutorial, we will learn about the steps to install and set up kubectl on Windows systems. 

 

Install kubectl on Windows

Users can install kubectl on Windows systems using either one of the below methods: 

  • Install kubectl binary with curl on Windows.
  • Install kubectl on Windows using Scoop or Chocolately.

 

Install kubectl binary with curl on Windows

In order to install the Kubernetes command-line tool with curl, follow the below steps: 

1. First, download the latest v1.22.0 release by using the following URL:

 

https://dl.k8s.io/release/v1.22.0/bin/windows/amd64/kubectl.exe

 

or if we have curl installed on the system, execute the following command to download the latest kubectl version: 

 

 curl -LO https://dl.k8s.io/release/v1.22.0/bin/windows/amd64/kubectl.exe

 

>> Note: In order to find out the latest stable kubectl version, visit https://dl.k8s.io/release/stable.txt.

 

2. (Optional) In order to validate the kubectl binary, download the kubectl checksum file by executing the following curl command: 

 

 curl -LO https://dl.k8s.io/v1.22.0/bin/windows/amd64/kubectl.exe.sha256

 

3. In order to validate the kubectl binary against the checksum file, use either one of the methods:

a) Manually compare CertUtil‘s output to the checksum file downloaded using the Command Prompt:

 

CertUtil -hashfile kubectl.exe SHA256
type kubectl.exe.sha256

 

b) Automate the verification using the -eq operator to get a True or False result using the PowerShell:

 

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

 

4. Next, add the kubectl binary into the user’s PATH

 

5. Finally, execute the following command to make sure that the available kubectl version is the same as the downloaded version: 

 

 kubectl version --client

 

>> Note: Docker Desktop for Windows adds its version of kubectl to the PATH. If the user has installed Docker Desktop before, they may need to remove the existing Docker Desktop’s kubectl or place their PATH entry before adding one.

 

Install kubectl on Windows using Scoop or Chocolately

1. First, execute the following command to install kubectl on Windows. Users can either use Scoop command-line installer or Chocolatey package manager to install the kubectl command-line tool.

 

Using Scoop Command-Line Installer: 

 

 $ scoop install kubectl

 

Using Chocolatey package manager: 

 

$ choco install kubernetes-cli

 

 2. Next, execute the following command to verify if the installed version is up-to-date: 

 

$ kubectl version --client

 

3. After that, navigate to the user’s home directory:

 

# If you're using cmd.exe, run: cd %USERPROFILE%
$ cd ~

 

4. Execute the following command to create the .kube directory:

 

 $ mkdir .kube

 

 5. Switch to the .kube directory. 

 

$ cd .kube

 

6. Finally, configure kubectl to use a remote Kubernetes cluster:

 

New-Item config -type file

 

>> Note: Users can edit the configuration file using any text editor of their choice, such as Notepad. 

 

Verify the kubectl Configuration 

In order for the kubectl command-line tool to find and access a Kubernetes cluster, it needs a kubeconfig file. The kubeconfig file will get automatically created when the users create a Kubernetes cluster using kube-up.sh or successfully deploy a Minikube cluster. The kubectl configuration is located at the ~/.kube/config path by default.

 

Check that kubectl is configured correctly by executing the following command:

 

 kubectl cluster-info

 

 If the user sees a URL response, then kubectl is correctly configured to access their cluster. If they see a message similar to the following, then the issue is that the kubectl command-line tool is not configured correctly, or kubectl cannot connect to a Kubernetes cluster.

 

The connection to the server <server-name:port> was refused - did you specify the right host or port?

 

For example, if the user intends to run a Kubernetes cluster on their local system or desktop, they will need a tool like Minikube to be installed for the smooth functioning of kubectl. After installing Minikube, users need to re-run the above command to check the kubectl configuration.

If the kubectl cluster-info command returns the URL response, but still the user’s can’t access their cluster, then execute the following command to verify the configuration:

 

kubectl cluster-info dump

 

Conclusion 

This tutorial presents the steps to install and set up the kubectl command-line tool on Windows systems. Hope this tutorial was helpful, and do reach out to us if you have any queries or suggestions.

Share this post

Share on facebook
Share on linkedin
Share on twitter
Share on whatsapp

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

Docker Consulting Services

Focus on your business, and let us work on your Docker Projects!
From what you are reading, it seems you are interested in Kubernetes and related technologies. If you have a moment to spare, please take a look at our Kubernetes Consulting Services, which might interest you even more!
Kubernetes Consulting Services

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

ServerHealers uses cookies.