A kubectl is an official Kubernetes command-line tool, used to run commands on Kubernetes clusters.
As the kubectl is distributed as a standalone binary it can be easily downloaded from official sources and installed on any Linux system, including Ubuntu.
In this post I will show you how to download and install the latest stable version of the kubectl on Ubuntu, although similar steps can be performed on any Linux system including CentOS, Amazon Linux, Debian, Linux Mint, etc.
Cool Tip: How to install Minikube on Ubuntu (VirtualBox)! Read more →
Install Kubectl on Ubuntu, CentOS, Amazon Linux
Use the following commands to install the latest stable version of the kubectl on Ubuntu:
$ KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
$ curl -LO "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
$ sudo install kubectl /usr/local/bin/kubectl
$ kubectl version --client -o json
- sample output -
{
"clientVersion": {
"major": "1",
"minor": "27",
"gitVersion": "v1.27.3",
"gitCommit": "25b4e43193bcda6c7328a6d147b1fb73a33f1598",
"gitTreeState": "clean",
"buildDate": "2023-06-14T09:53:42Z",
"goVersion": "go1.20.5",
"compiler": "gc",
"platform": "linux/amd64"
},
"kustomizeVersion": "v5.0.1"
}
The commands above do the following:
- Get the
kubectlversion number from the latest stable release and save it to theKUBECTL_VERSIONvariable. - Download the latest stable version of the
kubectlbinary. - Install the
kubectlbinary into a/usr/local/bin/directory. - Check the
kubectlversion to verify the installation.
These commands can also be used to install the kubectl on any Linux system, including CentOS, Amazon Linux, Debian, Linux Mint, etc.