Enable auto-completion for Kubectl in a Linux bash shell

Jack Roper
Nerd For Tech
Published in
3 min readAug 30, 2022

--

In this short post, we will demonstrate how to install kubectl, setup up auto-completion, and set an alias for kubectl in your bash shell.

When using kubectl commands to interact with your Kubernetes cluster (K8S), auto-completion can be very useful to avoid having to reference a cheat sheet constantly!

Setting an alias for kubectl on the command line, (commonly as k ), also helps save a lot of time when managing your cluster, and is also recommended for the CKA administrator exam as it is very time limited.

Install Kubectl on Linux

  1. Open your bash shell. Type kubectl . If you see the message ‘kubectl: command not found’, follow these steps to install kubectl . If it is installed, skip to step 7.

2. Download the latest kubectlrelease with the command:

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

3. Download the checksum file:

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

4. Validate the kubectl binary against the checksum file:

echo "$(cat kubectl.sha256)  kubectl" | sha256sum

--

--

Jack Roper
Nerd For Tech

A blog about DevOps & Cloud Tech. Specializing in Terraform, Kubernetes, Azure & Azure DevOps! ☁️