Skip to main content
Terraform code introduction

How to install kubectl to manage kubernetes

kubectl is the command-line tool that allows you to interact with a Kubernetes cluster. With kubectl, you can deploy applications, manage cluster resources, and inspect logs. Below, we outline the steps to install kubectl on different operating systems.

 

kubectl is the command-line tool that allows you to interact with a Kubernetes cluster. With kubectl, you can deploy applications, manage cluster resources, and inspect logs. Below, we outline the steps to install kubectl on different operating systems.

Prerequisites

Ensure that the version of kubectl you install is compatible with your Kubernetes cluster. It is recommended to use a version that is within one minor version of your cluster.

Installing on Linux

There are multiple ways to install kubectl on Linux:

Install Using curl

  1. Download the latest release:

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

    For ARM64 systems:

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

  2. Verify the checksum (optional):

    curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256" echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

  3. Install kubectl:

    sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

  4. Verify installation:

    kubectl version --client

Install Using Package Manager

Debian/Ubuntu:

  1. Update package index and install dependencies:

    sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl gnupg

  2. Add Kubernetes repository:

    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

  3. Install kubectl:

    sudo apt-get update sudo apt-get install -y kubectl

Red Hat/CentOS:

  1. Add Kubernetes repository:

    cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://pkgs.k8s.io/core:/stable:/v1.32/rpm/ enabled=1 gpgcheck=1 gpgkey=https://pkgs.k8s.io/core:/stable:/v1.32/rpm/repodata/repomd.xml.key EOF

  2. Install kubectl:

    sudo yum install -y kubectl

Installing on macOS

Install Using Homebrew

brew install kubectl

Install Using curl

  1. Download the latest release:

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

  2. Make it executable and move it to /usr/local/bin/:

    chmod +x kubectl sudo mv kubectl /usr/local/bin/kubectl

  3. Verify installation:

    kubectl version --client

Installing on Windows

Install Using Chocolatey

choco install kubernetes-cli

Install Using curl (PowerShell)

  1. Download the latest release:

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

  2. Move the binary to a directory in your system PATH.
  3. Verify installation:

    kubectl version --client

Configuring kubectl

Once installed, you need to configure kubectl to connect to a Kubernetes cluster. If using a cloud provider such as Google Kubernetes Engine (GKE) or Amazon Elastic Kubernetes Service (EKS), follow their specific authentication steps.

To check the cluster connection:

kubectl cluster-info

Conclusion

Installing kubectl is a straightforward process, and following these steps will ensure you have the latest version running on your system. Once installed, you can start managing your Kubernetes clusters efficiently.

Do you need any more information?

Recommended reading

Cloud infrastructure solutions

  • CloudPanda.io S.C.

  • VAT ID: PL5842818011

  • REGON: 522033432