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
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"
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
Install kubectl:
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Verify installation:
kubectl version --client
Install Using Package Manager
Debian/Ubuntu:
Update package index and install dependencies:
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
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
Install kubectl:
sudo apt-get update sudo apt-get install -y kubectl
Red Hat/CentOS:
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
Install kubectl:
sudo yum install -y kubectl
Installing on macOS
Install Using Homebrew
brew install kubectl
Install Using curl
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"
Make it executable and move it to /usr/local/bin/:
chmod +x kubectl sudo mv kubectl /usr/local/bin/kubectl
Verify installation:
kubectl version --client
Installing on Windows
Install Using Chocolatey
choco install kubernetes-cli
Install Using curl (PowerShell)
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"
- Move the binary to a directory in your system PATH.
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
Why it's worth using Helm charts for Kubernetes deployments
Docker vs. Kubernetes - what's the difference?
Docker and Kubernetes are both essential in the world of containerization and DevOps, but they serve different purposes.
How DevOps outsourcing can benefit your organization?
Every software house knows (well, we hope so!) how crucial DevOps is.
Cloud infrastructure solutions
- CloudPanda.io S.C.
- VAT ID: PL5842818011
- REGON: 522033432