Install and Set Up kubectl on Windows – Kubernetes

Before you begin

You must use a kubectl version that is within a minor version difference of the cluster. For example, a v1.27 client can communicate with control planes v1.26, v1.27, and v1.28. Using the latest compatible version of kubectl helps to avoid unforeseen problems.

Install kubectl on Windows

There are the following methods to install

kubectl on Windows:Install kubectl binary with curl on Windows Install on Windows

  • using Chocolatey, Scoop or winget
  • Install kubectl binary with curl on Windows

  1. Download the latest version v1.27.0.

    Or if you have curl installed, use this command:

  2. Validate the binary (optional)Download the kubectl file checksum:Validate the kubectl binary with the checksum file:Use the

    • command prompt to manually compare the output of CertUtil with the downloaded checksum file

    • :

    • Use PowerShell to automate verification using the -eq operator to get a true or false result:

    Append or prepend the

    binary folder kubectl

    to the

  3. PATH environment variable.

  4. Test to make sure the kubectl version

  5. is the same as the one downloaded

    :

    Or use this to get a detailed view

    of the version

  6. 😀 After installing the

  7. plugin, clean the installation files:

Install on Windows using Chocolatey, Scoop or winget

  1. To install kubectl on Windows, you can use the Chocolatey package manager, the Scoop command-line installer or the winget package manager.

    • Choco
    • Scoop
    • Winget
  2. Test to make sure the

  3. version you installed is up to date

  4. :Navigate to the home directory:Create the .kube directory:Change to

  5. the .kube directory you just created

  6. :Configure kubectl to use a remote Kubernetes cluster:Verify kubectl configuration For

  7. kubectl

  8. to

  9. find and access a Kubernetes cluster, you need a file

kubeconfig, which is created automatically when you create a cluster using kube-up.sh or successfully deploy a Minikube cluster. By default, the kubectl configuration is located in ~/.kube/config.

Verify that kubectl is configured correctly by getting the cluster status:If you see a URL response, kubectl is configured correctly to access your cluster.

If you see a message similar to the following, kubectl is not configured correctly or cannot connect to a Kubernetes cluster.

Connection to server <server-name:port> refused – did you specify the correct host or port?

For example, if you intend to run a Kubernetes cluster on your laptop (locally), you will first need to install a tool like Minikube and then run the commands listed above again.

If kubectl

cluster-info returns the url response but cannot access your cluster, to check if it is configured correctly, use:

Optional kubectl configurations and plugins

Enable shell

autocompletion

kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell, which can save you a lot of writing

.

The following are procedures for configuring autocomplete for PowerShell.

The kubectl completion script for PowerShell can be generated with the kubectl completion powershell command.

To do this in all shell sessions, add the following line to the $PROFILE file:

This command will regenerate the autocomplete script on each PowerShell startup. You can also add the generated script directly to the $PROFILE file.

To add the generated script to the $PROFILE file, run the following line at the PowerShell command prompt:

After reloading the shell, kubectl

autocomplete should be working

.

Install

kubectl convert plugin

A plugin for the kubectl kubernetes command-line tool, which allows you to convert manifests between different API versions. This can be particularly useful for migrating manifests to a non-deprecated API version with the latest version of Kubernetes. For more information, visit migrate to deprecated APIs

  1. Download the latest version with the command:

  2. Validate the binary (optional).

    Download the kubectl-convert checksum file:Validate the kubectl-convert binary with the checksum file:Use the

    • command prompt to manually compare the output of CertUtil’s with the downloaded checksum file

    • :

    • Use PowerShell to automate verification using the -eq operator to get a True or False result:

    Append or prepend the

    binary

    folder

    kubectl-convert

  3. to the PATH environment variable

  4. . Verify that the add-in

  5. was installed correctly.

    If you don’t see an error, it means the add-in has been successfully installed.

  6. After installing the plugin, clean up the installation files:

What’s next

  • Install Minikube
  • See the getting started guides for more information on creating clusters.
  • Learn how to launch and expose your app.
  • If you need access to a cluster that you did not create, see the Shared Cluster Access document.
  • Read the kubectl reference documents