Installing kubectl

Install kubectl on macOS, Linux, or Windows, verify it works, and understand how kubeconfig connects the CLI to a cluster.

What Is kubectl?

kubectl is the primary command-line tool for talking to Kubernetes clusters. It sends requests to the API Server so you can create, inspect, update, and delete resources.

Install on macOS

brew install kubectl

Install on Linux

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Install on Windows

You can install it with Chocolatey:

choco install kubernetes-cli

Verify the Install

kubectl version --client

If you already have access to a cluster, you can also run:

kubectl version

Connecting to a Cluster with kubeconfig

kubectl reads connection settings from a kubeconfig file, usually located at ~/.kube/config.

A kubeconfig file usually contains:

  • clusters: where the API Servers live
  • users: credentials or auth methods
  • contexts: named combinations of cluster + user + default namespace

Inspect kubeconfig

kubectl config view

That command prints the active configuration so you can see which cluster and user kubectl is using.

A Simple Workflow

kubectl version --client
kubectl config view
kubectl get nodes

If kubectl get nodes works, you are connected to a cluster successfully.

Why kubeconfig Matters

Think of kubeconfig like a contacts list for clusters. Instead of memorizing server addresses and credentials, you switch between named entries safely.

Without kubeconfig, kubectl would not know where to send requests or how to authenticate.

Common Problems

Command Not Found

The binary may not be in your PATH.

Connection Refused

Your kubeconfig may point to a cluster that is not running.

Unauthorized

Your kubeconfig may have expired credentials or the wrong user context.

Exercise

kubectl Role

What is the main job of `kubectl`?

Exercise

kubeconfig Purpose

Why is the kubeconfig file important?

Continue Learning

Explore Related Topics

Try the Tool

Related Resources