How to Install and Setup Kubectl on Ubuntu, Windows, and Mac

install kubectl on ubuntu, windows and mac

kubectl is the command-line tool for managing Kubernetes clusters. It allows you to deploy applications, inspect resources, and manage clusters. Whether you’re using Linux, Windows, or Mac, installing Kubectl is a simple process.

In this guide, we will walk you through how to install Kubectl on all three platforms. Let’s get started!

Install kubectl on Ubuntu Linux

Ubuntu users can install kubectl using various methods, including the apt package manager, Snap, or by downloading the binary directly.

Method 1: Using apt Package Manager

This method involves using Ubuntu’s default package manager to install kubectl.

1. Update your package list.

 # apt update

2. Install kubectl from the apt repository.

 # apt install -y kubectl

3. Verify that kubectl is installed correctly.

 # kubectl version --client

Output.

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47", GitTreeState:"clean", BuildDate:"2020-12-08T16:26:46Z", GoVersion:"go1.15.4", Compiler:"gc", Platform:"linux/amd64"}

Method 2: Using Snap

Snap is a package management system that simplifies the installation process.

1. Install Snap package manager for Ubuntu.

 # apt install snapd

2. Install kubectl via Snap.

 # snap install kubectl --classic

3. Check the kubectl version to verify the installation.

 # kubectl version --client

Output.

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"e9e2c6e", GitTreeState:"clean", BuildDate:"2021-05-12T14:21:32Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"linux/amd64"}

Method 3: Downloading Binary Directly

This method involves downloading the kubectl binary directly from the Kubernetes release page.

1. Download the latest release using the curl command.

 # curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

2. Make the binary executable.

 # chmod +x kubectl

3. Move the binary to a directory in your PATH.

 # mv kubectl /usr/local/bin/

4. Verify that kubectl is correctly installed.

 # kubectl version --client

Install kubectl on Windows

Windows users can install kubectl using Chocolatey, Scoop, or directly download the binary.

Method 1: Using Chocolatey

Chocolatey is a package manager for Windows that simplifies software installation.

1. Open PowerShell as Administrator and install Chocolatey if not already installed.

 # Set-ExecutionPolicy Bypass -Scope Process -Force; `[System.Net.ServicePointManager]::SecurityProtocol = `[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

2. Use Chocolatey to install kubectl.

 # choco install kubernetes-cli

3. Confirm that kubectl is installed correctly.

 # kubectl version --client

Method 2: Using Scoop

Scoop is another package manager for Windows that provides an easy way to install kubectl.

1. Open PowerShell and install Scoop if not already installed.

 # iwr -useb get.scoop.sh | iex

2. Use Scoop to install kubectl.

 # scoop install kubectl

3. Check the installation by verifying the kubectl version.

 # kubectl version --client

Output.

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"e9e2c6e", GitTreeState:"clean", BuildDate:"2021-05-12T14:21:32Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"windows/amd64"}

Method 3: Downloading Binary Directly

1. Download the latest release from the official Kubernetes release page.

2. Extract the kubectl.exe file to a directory of your choice.

3. Go to System Properties -> Advanced -> Environment Variables. Add the directory to the PATH variable.

4. Open Command Prompt or PowerShell to verify the installation.

 # kubectl version --client

Install kubectl on Mac

Mac users can install kubectl using Homebrew, MacPorts, or by downloading the binary directly.

Method 1: Using Homebrew

Homebrew is a popular package manager for macOS that simplifies software installation.

1. Install Homebrew, a widely used package manager for macOS.

 # /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Use Homebrew to install kubectl.

 # brew install kubectl

3. Verify the installation.

 # kubectl version --client

Output.

Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"e9e2c6e", GitTreeState:"clean", BuildDate:"2021-05-12T14:21:32Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"darwin/amd64"}

Method 2: Using MacPorts

MacPorts is another package manager for macOS that provides an easy way to install kubectl.

1. Go to the MacPorts Installation page and download the appropriate installer for your macOS version.

2. Use MacPorts to install kubectl.

 # port selfupdate && port install kubectl

3. Verify the installation.

 # kubectl version --client

Method 3: Downloading Binary Directly

This method involves downloading the kubectl binary directly from the Kubernetes release page.

1. Download the kubectl binary from the Kubernetes website.

 # curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"

2. Make the binary executable.

 # chmod +x kubectl

3. Move the executable to a directory in your system’s PATH.

 # mv kubectl /usr/local/bin/

4. Verify that kubectl is correctly installed.

 # kubectl version --client

Conclusion

In this article, we’ve covered multiple methods to install kubectl on Ubuntu, Windows, and Mac. Once set up, you can use Kubectl to manage your Kubernetes clusters with ease. Follow the steps in this guide to ensure a smooth installation process. Now you’re ready to work efficiently with your Kubernetes environments across any platform!

FAQs

1. What is kubectl and why do I need it?

kubectl is a command-line tool for interacting with Kubernetes clusters. You need it to deploy, manage, and troubleshoot applications running on your Kubernetes clusters.

2. Can I install kubectl on any Linux distribution other than Ubuntu?

Yes, kubectl can be installed on various Linux distributions. The methods may vary slightly, but generally, you can use the binary download method or package managers specific to the distribution.

3. How often should I update kubectl?

It's a good practice to keep kubectl updated to match the version of your Kubernetes cluster. This ensures compatibility and access to the latest features and bug fixes.

4. What should I do if kubectl commands are not recognized after installation?

Make sure that the directory containing kubectl is in your system's PATH. You may need to restart your terminal or system for the changes to take effect.

5. Can I use kubectl to manage clusters on cloud providers like AWS, Azure, and GCP?

Absolutely! kubectl can manage clusters on various cloud providers. You'll need to configure your kubeconfig file with the appropriate credentials and access information for your cloud-based clusters.

About Hitesh Jethva

I am Hitesh Jethva Founder and Author at LinuxBuz.com. I felt in love with Linux when i was started to learn Linux. I am a fan of open source technology and have more than 15+ years of experience in Linux and Open Source technologies.

View all posts by Hitesh Jethva