Skip to content

kubectl

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>

Documentation


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

Namespace


kubectl get namespaces
kubectl delete namespaces <name>

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
copy file into pod
kubectl cp /opt/linux/linux-peas.sh $NAMESPACE/$POD1:/tmp
kubectl cp /opt/linux/linux-priv-checker.sh $NAMESPACE/$POD1:/tmp
kubectl cp /opt/linux/linux-exploit-suggester.sh $NAMESPACE/$POD1:/tmp
shell
kubectl exec --stdin --tty $POD1 -n $NAMESPACE -- /bin/bash
kubectl exec --stdin --tty $POD1 -c <container-name> -n $NAMESPACE -- /bin/bash

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