Getting Started with kubectl on Windows CMD

Getting Started with kubectl on Windows CMD

 If you’re starting with Kubernetes on Windows, one of the first tools you’ll need is kubectl  the official command-line tool used to manage Kubernetes clusters. The good news is that you can install and run kubectl directly from Windows Command Prompt (cmd) in just a few minutes.


In this guide, you’ll learn how to install kubectl using curl, verify the installation, and start running basic Kubernetes commands.

What is kubectl?

kubectl is the Kubernetes command-line interface that lets you interact with your Kubernetes cluster. With it, you can:

  • View pods and nodes
  • Deploy applications
  • Check cluster status
  • Scale workloads
  • Debug services

It acts as the bridge between your local machine and the Kubernetes API server.

Prerequisites

Before you begin, make sure you have:

  • A Windows machine
  • Internet access
  • curl installed on your system

Most modern versions of Windows already include curl.

You can verify it by running:

curl --version

Step 1: Download kubectl Using CMD

Open Command Prompt and run the following command:

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

This command downloads the latest Windows-compatible kubectl.exe binary into your current directory.

Understanding the Command

  • curl.exe → explicitly calls the Windows curl executable
  • -L → follows redirects
  • -O → saves the file using its original filename

After completion, you should see:

kubectl.exe

in your current folder.

Step 2: Verify the Installation

Run:

kubectl.exe version --client

If installed correctly, you’ll see output similar to:

Client Version: v1.36.0

This confirms that kubectl is working properly.

Step 3: Add kubectl to PATH (Optional but Recommended)

To run kubectl from any folder:

1. Move kubectl.exe to a permanent folder such as:

C:\kubectl\

1. Add that folder to the Windows Environment Variables PATH.

After updating the PATH, reopen CMD and test:

kubectl version --client

Now you can use kubectl globally without typing the full path.

Step 4: Connect to a Kubernetes Cluster

kubectl needs a Kubernetes configuration file (kubeconfig) to communicate with a cluster.

Usually this file is located at:

C:\Users\<YourUsername>\.kube\config
You can check the current context using:
kubectl config current-context

Basic kubectl Commands for Beginners

  1. View Cluster Nodes
  2. kubectl get nodes
  3. View Running Pods
  4. kubectl get pods
  5. Check All Namespaces
  6. kubectl get namespaces
  7. Get Cluster Information
  8. kubectl cluster-info

Common Errors and Fixes

1. 'kubectl' is not recognized

Cause:kubectl.exe is not in your PATH.
Fix: Add the folder containing kubectl.exe to the Windows PATH environment variable.

2. Connection Refused Error

Cause: Kubernetes cluster is not configured or reachable.
Fix: Ensure your kubeconfig file is correct and your cluster is running.

3. Unauthorized Access

Cause: Missing permissions.
Fix: Verify your Kubernetes credentials and role permissions.

Why Use CMD for Kubernetes?

Using Command Prompt is lightweight and simple for Windows users. While many developers prefer PowerShell or WSL, CMD works perfectly fine for:

  • Installing tools
  • Running quick commands
  • Managing clusters
  • Learning Kubernetes basics

Final Thoughts

Installing kubectl on Windows CMD is straightforward and beginner-friendly. With a single curl command, you can quickly set up Kubernetes management tools and start interacting with clusters right from your terminal.

Whether you’re a DevOps engineer, developer, or Kubernetes beginner, learning kubectl is an essential step toward mastering container orchestration.

Post a Comment

0 Comments