01 Overview
Kubernetes schedules containers across a cluster of machines, restarts failed ones, scales replicas up and down, and rolls out changes with zero downtime. This guide installs kubectl, the CLI used to talk to any cluster — managed (EKS/GKE/AKS) or self-hosted.
→ official documentation02 Installation
Pick a platform. Each step is copy-pasteable on its own.
01 Download the signing key
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
02 Add the apt repository
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
03 Install kubectl
sudo apt-get update sudo apt-get install -y kubectl
04 Verify
kubectl version --client
01 Add the yum repository
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/ enabled=1 gpgcheck=1 gpgkey=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/repodata/repomd.xml.key EOF
02 Install kubectl
sudo dnf install -y kubectl
03 Verify
kubectl version --client
01 Install via Homebrew
brew install kubectl
02 Verify
kubectl version --client
Note — commands assume sudo privileges and an up-to-date package index. Pin a specific version in production rather than tracking latest.
03 Install script
The steps above bundled into a single idempotent shell script for provisioning boxes unattended.
install-kubernetes.sh
Ubuntu/Debian target · safe to re-run · exits non-zero on failure
04 Cheatsheet
The commands reached for most often once Kubernetes is installed.
| Command | What it does |
|---|---|
| kubectl get pods -A | List pods in every namespace |
| kubectl get nodes -o wide | List cluster nodes with details |
| kubectl apply -f file.yaml | Create or update resources from a manifest |
| kubectl describe pod <name> | Show events and status for a pod |
| kubectl logs -f <pod> | Stream logs from a pod |
| kubectl exec -it <pod> -- sh | Open a shell inside a pod |
| kubectl rollout restart deploy/<name> | Restart a deployment's pods |
| kubectl scale deploy/<name> --replicas=5 | Scale a deployment |
| kubectl config use-context <ctx> | Switch cluster context |