Skip to content

Basic Pod Commands

# 🐳 Basic Pod Commands

This section covers essential commands and YAML for working with Pods — the smallest unit in Kubernetes.

---

## ✅ Create a Simple Pod

```bash
kubectl run nginx-pod --image=nginx

🛠️ Generate Pod YAML (Dry Run)

kubectl run nginx --image=nginx --dry-run=client -o yaml

This is useful for producing a manifest file you can tweak before applying.


🔍 Inspect a Pod's Image

kubectl get pod <pod-name> -o jsonpath="{.spec.containers[*].image}"

🗑️ Delete a Pod

kubectl delete pod <pod-name>

Example:

kubectl delete pod webapp

📄 Create a Pod from YAML

You can define a Pod manually in a YAML file, even with a broken image (useful for testing failure states):

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis123  # incorrect image for demo/testing

Save this to redis-pod.yaml and apply it:

kubectl apply -f redis-pod.yaml

✅ Summary

  • Pods are ephemeral units running your containers
  • Use kubectl run for quick tests, or YAML for reusable configurations
  • Always validate with kubectl describe and kubectl logs if things go wrong