Table of Contents
← Go Back

Kubernetes Commands 101 Cheat Sheet

To administrate a Kubernetes cluster locally on bare metal hardware is not always easy. You have to always remember every command for different tasks or look it up while your thoughts are on how to fix stuff and not how to write the command correctly.

image searching meme

To make this "look up the right command" easy, here is a small cheat sheet with the most important commands I personally use on my cluster:


Cluster operations

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# simple cluster endpoint information about services and master node
kubectl cluster-info

# show Kubernetes version on client and server
kubectl version

# show configuration file of the cluster
kubectl config view

# show all resources of a specific namespace
kubectl get all -n NAMESPACE

# show all resources over all namespaces
kubectl get all -A

# show all resources of the cluster in a CLI GUI with k9s
k9s

Node operations

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# show all cluster nodes
kubectl get nodes

# annotate a node with a tag
kubectl annotate node NODE_NAME KEY = VALUE

# label a node
kubectl label node NODE_NAME LABEL = VALUE

# mark node as schedulable
kubectl uncordon node NODE_NAME

# mark node as unschedulable
kubectl cordon node NODE_NAME

# drain a node in preperation for maintenance
kubectl drain node NODE_NAME

Pod operations

bash
1
2
3
4
5
6
7
8
9
10
11
# show all pods with wider informations
kubectl get pods -o wide -n NAMESPACE

# show all pods over all namespaces
kubectl get pods -A

# describe deployment of pod
kubectl describe POD_NAME -n NAMESPACE

# log into pod shell
kubectl exec -it POD_NAME -n NAMESPACE -- /bin/bash # or /bin/sh

Namespace operations

bash
1
2
# show all namespaces
kubectl get ns