Kubernetes Pods

Managing Kubernetes pods

List Pods

kubectl get pods # list pods in current namespace
kubectl get pods -A # list pods in all namespaces
kubectl get pods -o wide # list with more details
kubectl get pods --watch # watch pods in real-time

Create Pod

kubectl run nginx --image=nginx # create pod from image
kubectl run nginx --image=nginx --dry-run=client -o yaml # generate YAML
kubectl apply -f pod.yaml # create from YAML file

Describe and Logs

kubectl describe pod pod-name # detailed pod info
kubectl logs pod-name # view pod logs
kubectl logs -f pod-name # stream logs
kubectl logs pod-name -c container-name # logs from specific container

Execute Commands

kubectl exec -it pod-name -- /bin/bash # interactive shell
kubectl exec pod-name -- command # run command in pod

Delete Pod

kubectl delete pod pod-name # delete pod
kubectl delete pod pod-name --grace-period=0 --force # force delete
kubectl delete pods --all # delete all pods

Port Forward

kubectl port-forward pod-name 8080:80 # forward port 8080 to pod port 80