Pods

Pods – Pods are the smallest deployable units of computing that you can create and manage in Kubernetes. A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.

  1. List one or more pods.

kubectl get pod
  1. List pods Sorted by Restart Count.

kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
  1. Get all running pods in the namespace.

kubectl get pods --field-selector=status.phase=Running
  1. Delete a pod.

kubectl delete pod <pod_name>
  1. Display the detailed state of a pods.

kubectl describe pod <pod_name>
  1. Create a pod.

kubectl create pod <pod_name>
  1. Execute a command against a container in a pod.

kubectl exec <pod_name> -c <container_name> <command>
  1. Get an interactive shell on a single-container pod.

kubectl exec -it <pod_name> /bin/sh
  1. Display Resource usage (CPU/Memory/Storage) for pods.

kubectl top pod
  1. Add or update the annotations of a pod.

kubectl annotate pod <pod_name> <annotation>
  1. Add or update the label of a pod.

kubectl label pods <pod_name> new-label=<label name>
  1. Get pods and show labels.

kubectl get pods --show-labels
  1. Listen on a port on the local machine and forward to a port on a specified pod.

kubectl port-forward <pod name> <port number to listen on>:<port number to forward to>

Last updated