DEV Community

Dechen Tshering
Dechen Tshering

Posted on

1 1

πŸš€ Kubernetes Pod Commands & YAML Guide – Quick Reference for Devs & DevOps

Whether you're new to Kubernetes or want a clean reference sheet, here’s a quick guide to working with Kubernetes Pods using the CLI and YAML definitions.
This post includes essential commands, how to access pods and containers and how to create pods using YAML.

Essential kubectl Commands for Pods.

Create a pod
kubectl run <pod-name> --image=<image-name>

List all pods
kubectl get pods

List pods with extended details (IP address, node, etc.)
kubectl get pods -o wide

Access a running pod shell
kubectl exec -it <pod-name> -- bash

Access a specific container inside a multi-container pod
kubectl exec -it <pod-name> -c <container-name> -- bash

Describe pod details
kubectl describe pod <pod-name>

Get detailed node information (container runtime, etc.)
kubectl get nodes -o wide

Delete a pod
kubectl delete pod <pod-name>

Create a Pod Using YAML

vim pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: abc
spec:
  containers:
  - name: c1
    image: nginx
Enter fullscreen mode Exit fullscreen mode

Commands:

Create resources from YAML
kubectl create -f pod.yaml

Delete resources from YAML
kubectl delete -f pod.yaml

Access Shell Inside Pod/Container

Access the shell of a pod
kubectl exec -it <pod-name> -- sh

Access a specific container in a pod
kubectl exec -it <pod-name> -c <container-name> -- sh

If this helped you or you'd like to keep a quick reference around, feel free to bookmark or share this post! πŸš€
Let’s keep growing together in the world of Cloud Native, Kubernetes, and DevOps.

Top comments (0)