Kubectl Cheatsheet

Download kubectl to your Linux / Mac laptop

Linux:

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

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

kubectl version --client

Macos, M1 architecture:

1
2
3
4
5
6
7
8
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"

chmod +x ./kubectl

sudo mv ./kubectl /usr/local/bin/kubectl
sudo chown root: /usr/local/bin/kubectl

kubectl version --client

How to merge kubectl config files:

1
2
export KUBECONFIG=~/.kube/config:~/someotherconfig
kubectl config view --flatten

How to get list of nodes:

1
kubectl get nodes

How to see CPU load and memory usage for nodes:

1
kubectl top nodes

How to get pods running on specific node:

1
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy