🟦 Day 49: Pods & kubectl

Ritesh SinghRitesh Singh
3 min read

Welcome to Day 49 of Kubernetes learning.
Today we’ll dive into Pods (the smallest deployable unit in Kubernetes) and learn how to manage them using kubectl.


📌 1. What is a Pod?

A Pod is the smallest deployable unit in Kubernetes.
It represents a single instance of a running process in your cluster.

🔹 Key Features:

  • A Pod can contain one or more containers (but usually one).

  • Containers inside the same Pod:

    • Share the same network namespace (same IP and ports).

    • Can communicate over localhost.

    • Can share volumes (storage).

  • A Pod is always scheduled on a single Node in the cluster.

👉 Think of a Pod as a wrapper around your container(s) with extra Kubernetes features (network, storage, lifecycle).


📌 2. Imperative vs Declarative in Kubernetes

Kubernetes supports two ways of interacting with resources.

🔹 Imperative (command-based)

You directly tell Kubernetes what to do immediately.

Examples:

# Run a Pod with nginx image
kubectl run nginx --image=nginx

# List all Pods
kubectl get pods

# Delete a Pod
kubectl delete pod nginx

✔️ Good for quick testing, not ideal for production.

🔹 Declarative (YAML manifest)

You describe the desired state in a YAML file, and Kubernetes ensures that state. Example: nginx-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80

Apply it:

kubectl apply -f nginx-pod.yaml

Verify:

kubectl get pods -o wide
kubectl describe pod nginx-pod

Delete it:

kubectl delete -f nginx-pod.yaml

👉 In real DevOps work → Declarative YAML is the standard.

📌 3. Useful kubectl Commands for Pods

# Get all Pods
kubectl get pods

# Describe details of a Pod
kubectl describe pod <pod-name>

# Check Pod logs
kubectl logs <pod-name>

# Exec into a Pod (like SSH into container)
kubectl exec -it <pod-name> -- /bin/bash

# Forward Pod port to localhost (for testing)
kubectl port-forward pod/<pod-name> 8080:80

👉 To stop port-forwarding, press Ctrl + C.


Pod Lifecycle

Pods are ephemeral:

  • If a Pod crashes, it does not automatically restart.

  • Kubernetes can restart the container inside a Pod if configured with restartPolicy.

  • For scaling and self-healing, we use ReplicaSets and Deployments (covered in Day 50).

When to Use Pods Directly?

Rarely used alone in production.

Mostly for:

  • Testing a single container quickly.

  • Debugging.

  • Learning basics of Kubernetes.

In real-world scenarios → use Deployments for managing Pods.

Summary

  • Pod = smallest deployable unit in Kubernetes.

  • Pods can contain multiple containers (sharing network + storage).

  • Imperative = direct commands (fast, temporary).

  • Declarative = YAML manifests (recommended, scalable).

  • Pods are ephemeral → for real apps, use ReplicaSets/Deployments.


❤️ Follow My DevOps Journey

Ritesh Singh
🌐 LinkedIn | 📝 Hashnode | GITHUB

0
Subscribe to my newsletter

Read articles from Ritesh Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ritesh Singh
Ritesh Singh

Hi, I’m Ritesh 👋 I’m on a mission to become a DevOps Engineer — and I’m learning in public every single day.With a full-time commitment of 8–10 hours daily, I’m building skills in: ✅ Linux✅ Git & GitHub✅ Docker & Kubernetes✅ AWS EC2, S3✅ Jenkins, GitHub Actions✅ Terraform, Prometheus, Grafana I post daily blogs on Hashnode, push projects to GitHub, and stay active on LinkedIn and Twitter/X. Let’s connect, collaborate, and grow together 🚀 #100DaysOfDevOps #LearningInPublic #DevOps