Kubernetes (K8s) Pod Fundamentals for Beginners (Easy Learning Guide)

Kubernetes is one of the most in-demand tools in DevOps, and understanding Pods is the first step toward mastering it. Today, I’ll walk you through everything I learned about Pods, including creating them using the CLI, generating YAML/JSON manifests, applying labels, debugging, and deleting Pods.

ALSO READ:

Click here to go to the GitHub repos link

Kubernetes Creating a Pod Using

# You can create a simple Pod directly from the CLI
kubectl run nginx-pod --image=nginx:latest
Check if the Pod is running
kubectl get pods
kubectl get pods -o wide
Understanding Pod Details
# To view full details
kubectl describe pod nginx-pod

You can see:

  • Pod creation time
  • Node it is running on
  • Image ID
  • Container state (Running / Waiting / Terminated)
  • Restart count
  • Events (pulling, created, started)
  • Volumes and service accounts

Generate YAML/JSON

# yaml Output

kubectl run mypod --image=nginx:latest --dry-run=client -o yaml
# Save the manifest yaml
kubectl run mypod --image=nginx:latest --dry-run=client -o yaml > nginx-pod.yaml

# JSON Output

kubectl run mypod --image=nginx:latest --dry-run=client -o json
# Save the manifest in json
kubectl run mypod --image=nginx:latest --dry-run=client -o json > nginx-pod.json

Creating a Pod Using a YAML Manifest

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    env: dev
    type: frontend
    version: 1.0.0
spec:
  containers:
  - name: nginx-pod
    image: nginx:latest
    ports:
    - containerPort: 80
Apply it
kubectl apply -f simple-pod.yml

# Check pod labels

kubectl get pods --show-labels

Deleting Pods

# To delete the pod
kubectl delete pod nginx-pod

Example screenshots:


[root@tech-k8s-1 test]# kubectl apply -f simple-pod.yml
pod/nginx-pod created
[root@tech-k8s-1 test]# kubectl get pods
NAME        READY   STATUS    RESTARTS      AGE
nginx-pod   1/1     Running   1 (74m ago)   77m
[root@tech-k8s-1 test]# kubectl get pods --show-labels
NAME        READY   STATUS    RESTARTS      AGE   LABELS
nginx-pod   1/1     Running   1 (74m ago)   77m   env=dev,type=frontend,version=1.0.0

Leave a Comment