K8s cheat sheet
Documentation
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
ALL
Namespace
Node
Pods
kubectl get pods --namespace=ecorp
kubectl get pods --all-namespaces
kubectl get pods -o wide --namespace=ecorp
kubectl get pods -o wide --all-namespaces
kubectl get pods --show-labels --all-namespaces
kubectl describe pods <my-pod-name>
Containers (get images)
kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{"\nPod: "}{.metadata.name}{" ==> Containers: "}{range .spec.containers[*]}{.image}{" | "}{end}{end}' | sort
# output:
# Pod: <pod-name> ==> Containers: <container-image-1> | <container-image-2> | <container-image-3> |
# Pod: <pod-name> ==> Containers: <container-image-1> | <container-image-2> | <container-image-3> |
# Pod: <pod-name> ==> Containers: <container-image-1> | <container-image-2> | <container-image-3> |
Containers (get name)
kubectl get pods --namespace=ecorp -o jsonpath='{range .items[*]}{"\nPod: "}{.metadata.name}{" ==> Containers: "}{range .spec.containers[*]}{.name}{" | "}{end}{end}' | sort
# output:
# Pod: <pod-name> ==> Containers: <container-name-1> | <container-name-2> | <container-name-3> |
# Pod: <pod-name> ==> Containers: <container-name-1> | <container-name-2> | <container-name-3> |
# Pod: <pod-name> ==> Containers: <container-name-1> | <container-name-2> | <container-name-3> |
kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{"\nPod: "}{.metadata.name}{" ==> Containers: "}{range .spec.containers[*]}{.name}{" | "}{end}{end}' | sort
Service
Secret
Logs
kubectl logs <pod-name> --namespace=ecorp # dump
kubectl logs <pod-name> -c <container-name> --namespace=ecorp # dump
Shell in pod
kubectl exec --stdin --tty <pod-name> --namespace=<namespace-name> -- /bin/sh
kubectl exec --stdin --tty <pod-name> -c <container-name> --namespace=<namespace-name> -- /bin/sh
kubectl exec --stdin --tty <pod-name> --namespace=<namespace-name> -- /bin/bash
kubectl exec --stdin --tty <pod-name> -c <container-name> --namespace=<namespace-name> -- /bin/bash