Skip to content

kubectl

Documentation


https://kubernetes.io/docs/reference/kubectl/cheatsheet/

tmux setenv NAMESPACE <namespace>
tmux setenv POD1 <pod-1-name>
tmux setenv POD2 <pod-2-name>
tmux setenv POD3 <pod-3-name>
tmux setenv SEC1 <secret-name>

Namespace


kubectl get namespaces

Node


list

kubectl get nodes -n $NAMESPACE
kubectl get nodes -A

Pods


list

kubectl get pods -n $NAMESPACE
kubectl get pods -n $NAMESPACE -o wide
kubectl get pods -n $NAMESPACE -o wide --show-labels
details
kubectl describe pods $POD1 -n $NAMESPACE
kubectl describe pods $POD2 -n $NAMESPACE
kubectl describe pods $POD3 -n $NAMESPACE
containers
kubectl get pods -n $NAMESPACE -o jsonpath='{range .items[*]}{"\nPod: "}{.metadata.name}{"  ==> Containers:  "}{range .spec.containers[*]}{.image}{" | "}{end}{end}' | sort
containers - names
kubectl get pods -n $NAMESPACE -o jsonpath='{range .items[*]}{"\nPod: "}{.metadata.name}{"  ==> Containers:  "}{range .spec.containers[*]}{.name}{" | "}{end}{end}' | sort
shell
kubectl exec --stdin --tty $POD1 -n $NAMESPACE -- /bin/sh
kubectl exec --stdin --tty $POD1 -c <container-name> -n $NAMESPACE -- /bin/sh

Service


kubectl get services -n $NAMESPACE

Secret


list

kubectl get secret -n $NAMESPACE
details
kubectl get secret $SEC1 -n $NAMESPACE
kubectl describe secret $SEC1 -n $NAMESPACE
kubectl get secret $SEC1 -n $NAMESPACE -o jsonpath='{.data}'

Events


kubectl get events -n $NAMESPACE

Logs


kubectl logs $POD1 -n $NAMESPACE
kubectl logs $POD1 -c <container-name> -n $NAMESPACE  

ALL

kubectl get all -n $NAMESPACE

Cluster info


kubectl cluster-info