Pod Example: Create a Simple Pod - neerajk555/Kubernetes GitHub Wiki
Creating a Pod in Kubernetes is one of the foundational tasks when working with Kubernetes. A Pod is the smallest and simplest unit in the Kubernetes object model. It represents a single running process in your cluster and can contain one or more containers (usually one).
What is a Pod? A Pod:
Encapsulates one or more containers (e.g., Docker containers).
Shares network and storage resources among containers.
Is ephemeral — once it dies, it is not restarted automatically unless managed by a higher-level controller like a Deployment.
Step-by-Step: Creating a Pod We'll create a pod that runs an nginx container using a YAML manifest.
Step 1: Write a Pod YAML file Let’s name it nginx-pod.yaml
Step 2: Create the Pod using kubectl
kubectl apply -f nginx-pod.yaml
Step 3: Verify the Pod
kubectl get pods
This lists all the Pods and shows if your Pod is running.
kubectl describe pod nginx-pod
Gives detailed information including events, container status, and networking.
kubectl logs nginx-pod
Shows the logs from the container inside the Pod.
Step 4: Test the Pod
Since this is a single Pod and not exposed externally, you can run a temporary busybox Pod to test connectivity:
kubectl run tmp-shell --rm -i -t --image=busybox -- /bin/sh
Then from inside that shell:
wget nginx-pod
Step 5: Clean Up
To delete the Pod: kubectl delete pod nginx-pod
** When to Use a Pod Directly?**
Pods are usually not created directly in production.
Instead, you use Deployments, ReplicaSets, etc., which manage Pods and handle scaling, restarts, and updates.
Direct Pods are great for learning, debugging, or running short-lived jobs.