What kubectl is
kubectl is the command line tool for Kubernetes. It talks to a cluster and lets you deploy apps, inspect resources and read logs. To use it you also need a cluster (for example Minikube on your machine, a kubeadm cluster or a cloud one).
Method 1: Snap
Step 1: Install kubectl
sudo snap install kubectl --classic

snapis the Snap package manager.installinstalls a package.kubectlis the package name.--classiclets the package access the whole system, which kubectl needs.
Step 2: Check it
kubectl version --client

versionshows the version of kubectl.--clientshows the client version only (without connecting to a cluster).
Method 2: The binary
Step 1: Download kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

curlfetches data from a web server.-Lfollows redirects.-Osaves the file under its own name.- The part in
$(...)asks for the latest stable version number.
Step 2: Download the checksum
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

Step 3: Check the file
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

You should see kubectl: OK.
Step 4: Install the binary
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

-o root -g rootsets the owner and group to root.-m 0755sets the permissions (the owner can write, everyone can read and run).- The file goes to
/usr/local/bin/kubectl.
Step 5: Check it
kubectl version --client

Next steps
- For a local cluster, install Minikube or kind.
- For a real cluster, install
kubeadmandkubelet, or use a managed Kubernetes service. - Copy the kubeconfig file of your cluster to
~/.kube/config, then test withkubectl get nodes.
What Kubernetes does
- Self-healing. It replaces failed containers.
- Resource management. It shares CPU and memory in a smart way.
- Rollouts and rollbacks. It updates apps step by step, and can go back.
- Horizontal scaling. It adds or removes copies of your app as the load changes.
- Service discovery and load balancing.
Quick recap
sudo snap install kubectl --classicis the fast way.- Or download the binary, check the checksum and install it.
- Check with
kubectl version --client.