<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[kubernetes]]></title><description><![CDATA[kubernetes]]></description><link>https://a-comprehensive-guide-to-kubernetes-pods.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 25 Jun 2026 20:34:40 GMT</lastBuildDate><atom:link href="https://a-comprehensive-guide-to-kubernetes-pods.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Comprehensive Guide to Kubernetes Pods]]></title><description><![CDATA[1. What is a Pod?

A Pod is the smallest building block in Kubernetes.

A Pod contains one or more running containers.

Pods are always created inside a namespace for logical separation.

Pods are the actual running instances of your application.

Ea...]]></description><link>https://a-comprehensive-guide-to-kubernetes-pods.hashnode.dev/a-comprehensive-guide-to-kubernetes-pods</link><guid isPermaLink="true">https://a-comprehensive-guide-to-kubernetes-pods.hashnode.dev/a-comprehensive-guide-to-kubernetes-pods</guid><category><![CDATA[Pod, kubernetes]]></category><category><![CDATA[Kubernetes pod lifecycle]]></category><dc:creator><![CDATA[Madhu Reddy]]></dc:creator><pubDate>Thu, 11 Sep 2025 22:32:12 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-1-what-is-a-pod"><strong>1. What is a Pod?</strong></h2>
<ul>
<li><p>A <strong>Pod</strong> is the <strong>smallest building block</strong> in Kubernetes.</p>
</li>
<li><p>A Pod contains <strong>one or more running containers</strong>.</p>
</li>
<li><p>Pods are always created inside a <strong>namespace</strong> for logical separation.</p>
</li>
<li><p>Pods are the <strong>actual running instances</strong> of your application.</p>
</li>
<li><p>Each Pod has a <strong>unique IP address</strong> within the cluster.</p>
</li>
</ul>
<p><strong>Note :</strong> Normally, <strong>application pods</strong> do <strong>not</strong> run on the master (control plane) node.<br />They only run on <strong>worker nodes</strong>.</p>
<p>But some <strong>system pods</strong> (like DNS, networking, API server helpers, etc.) may run on the master node because Kubernetes itself needs them for management. These are part of the <strong>control plane</strong> or <strong>system namespaces</strong> (like <code>kube-system</code>).</p>
<ul>
<li><p><strong>Your app pods</strong> → run on worker nodes.</p>
</li>
<li><p><strong>System/management pods</strong> → may run on master node (to keep the cluster working).</p>
</li>
</ul>
<hr />
<h2 id="heading-2-where-pods-fit-in-the-kubernetes-world">2. Where Pods Fit in the Kubernetes World</h2>
<ol>
<li><p><strong>Master Node / Control Plane</strong><br /> The brain of Kubernetes – it has the <strong>scheduler</strong>, which plans and decides <strong>which worker node should run your pod</strong>.</p>
</li>
<li><p><strong>Worker Nodes</strong><br /> The machines (virtual or physical) that actually <strong>run the pods</strong> assigned by the master.</p>
</li>
<li><p><strong>Kubelet</strong><br /> A helper program on each worker node. It <strong>talks to the master</strong>, pulls the container images, starts the containers, and keeps checking that the pods are running properly.</p>
</li>
<li><p><strong>Container Runtime</strong><br /> Software like <strong>Docker</strong> or <strong>containerd</strong> that actually runs the containers inside each pod</p>
</li>
</ol>
<hr />
<h2 id="heading-3-pod-characteristics">3. Pod Characteristics</h2>
<ol>
<li><p><strong>Smallest Unit</strong></p>
<ul>
<li>A Pod is the smallest thing you can create and run in Kubernetes.</li>
</ul>
</li>
<li><p><strong>Contains Containers</strong></p>
<ul>
<li><p>A Pod can have <strong>one or more containers</strong> inside it.</p>
</li>
<li><p>Most of the time, it has only one container.</p>
</li>
</ul>
</li>
<li><p><strong>Unique IP Address</strong></p>
<ul>
<li><p>Each Pod gets its <strong>own IP address</strong> in the cluster.</p>
</li>
<li><p>All containers inside the pod share that IP.</p>
</li>
</ul>
</li>
<li><p><strong>Shared Network</strong></p>
<ul>
<li>Containers inside the same Pod can talk to each other using <a target="_blank" href="http://localhost/"><code>localhost</code></a>.</li>
</ul>
</li>
<li><p><strong>Shared Storage</strong></p>
<ul>
<li>Containers inside a Pod can use the <strong>same storage volumes</strong>.</li>
</ul>
</li>
<li><p><strong>Ephemeral (Temporary)</strong></p>
<ul>
<li><p>Pods are not permanent.</p>
</li>
<li><p>If a pod dies, Kubernetes creates a new one, usually with a new IP.</p>
</li>
</ul>
</li>
<li><p><strong>Namespace Scoped</strong></p>
<ul>
<li>Pods live inside a <strong>namespace</strong> (like <code>dev</code>, <code>test</code>, <code>prod</code>) for logical separation.</li>
</ul>
</li>
</ol>
<hr />
<h2 id="heading-4-types-of-pods">4. Types of Pods</h2>
<h3 id="heading-a-single-container-pod">a) Single-Container Pod</h3>
<ul>
<li><p>Only <strong>one</strong> container inside.</p>
</li>
<li><p>Example: Running <strong>just a web server</strong>.</p>
</li>
</ul>
<h3 id="heading-understanding-kubernetes-pod-yaml">Understanding Kubernetes Pod YAML</h3>
<p>YAML is the way we tell Kubernetes <strong>what we want</strong>. Kubernetes then takes this YAML and makes it real in the cluster.</p>
<p>Every Kubernetes YAML follows a similar structure:</p>
<pre><code class="lang-plaintext">apiVersion: v1         # Which version of Kubernetes API to use
kind: Pod              # What we are creating (Pod, Deployment, Service, etc.)
metadata:              # Basic information (name, namespace, labels)
  name: my-first-pod
  namespace: default
spec:                  # The "specification" of the Pod
  containers:          # List of containers inside this Pod
    - name: nginx-container
      image: nginx:latest
      ports:
        - containerPort: 80
</code></pre>
<h3 id="heading-key-sections-explained">Key Sections Explained</h3>
<ol>
<li><p><strong>apiVersion</strong></p>
<ul>
<li><p>Tells Kubernetes which version of the object definition to use.</p>
</li>
<li><p>For Pods → usually <code>v1</code>.</p>
</li>
</ul>
</li>
<li><p><strong>kind</strong></p>
<ul>
<li><p>Defines what you’re creating.</p>
</li>
<li><p>Example: <code>Pod</code>, <code>Deployment</code>, <code>Service</code>, <code>ConfigMap</code>.</p>
</li>
</ul>
</li>
<li><p><strong>metadata</strong></p>
<ul>
<li><p>Name, labels, and namespace.</p>
</li>
<li><p>Example: <code>name: my-first-pod</code> → this pod’s name in the cluster.</p>
</li>
<li><p><code>namespace: default</code> → lives in the default namespace.</p>
</li>
</ul>
</li>
<li><p><strong>spec</strong></p>
<ul>
<li><p>The heart of the configuration.</p>
</li>
<li><p>Defines how the pod should run: containers, images, ports, volumes, etc.</p>
</li>
<li><p>A list because a Pod can have multiple containers.</p>
</li>
<li><p>Each container needs:</p>
</li>
<li><p><code>name</code> → a unique name inside the pod</p>
</li>
<li><p><code>image</code> → the container image (from Docker Hub or registry</p>
</li>
<li><p><code>ports</code> → which port this container listens on</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-how-kubernetes-uses-this-yaml">How Kubernetes Uses This YAML</h3>
<ol>
<li>You <strong>apply</strong> the YAML:</li>
</ol>
<pre><code class="lang-plaintext">kubectl apply -f pod.yaml
</code></pre>
<ol start="2">
<li>Kubernetes <strong>reads</strong> it and asks:</li>
</ol>
<ul>
<li><p>What kind (<code>Pod</code>)?</p>
</li>
<li><p>What’s the name (<code>my-first-pod</code>)?</p>
</li>
<li><p>What container(s) should I run (<code>nginx:latest</code>)?</p>
</li>
</ul>
<ol start="3">
<li><p>The <strong>scheduler</strong> finds a worker node to host the pod.</p>
</li>
<li><p>The <strong>kubelet</strong> on that node pulls the image and starts the container.</p>
</li>
<li><p>You can check it with:</p>
</li>
</ol>
<pre><code class="lang-plaintext">kubectl get pods 
kubectl get pods -n [namespace name]
</code></pre>
<hr />
<h3 id="heading-b-multi-container-pod">b) Multi-Container Pod</h3>
<p>A <strong>multi-container pod</strong> is a pod that runs <strong>two or more containers</strong> together.<br />All containers in the pod share:</p>
<ul>
<li><p><strong>Network namespace</strong> → They can communicate via localhost and share the same IP/ports.</p>
</li>
<li><p><strong>Storage volumes</strong> → They can read/write to the same mounted volumes.</p>
</li>
<li><p><strong>Pod lifecycle</strong> → They start, stop, and restart together.</p>
</li>
</ul>
<h3 id="heading-common-use-case-sidecar-pattern"><strong>Common Use Case: Sidecar Pattern</strong></h3>
<p>The <strong>Sidecar Pattern</strong> pairs a main container with a helper container to add functionality without modifying the main app.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755277766741/c8efdde5-2fd6-4682-8527-d0f147bfa6c0.png?auto=compress,format&amp;format=webp" alt /></p>
<p><strong>Example:</strong></p>
<ul>
<li><p><strong>Main App Container</strong> → Runs your primary application (e.g., web server, API).</p>
</li>
<li><p><strong>Helper/Sidecar Container</strong> → Performs supporting tasks such as:</p>
</li>
<li><p>Log collection and shipping (e.g., Fluent Bit)</p>
</li>
<li><p>Service proxy (e.g., Envoy, Istio sidecar)</p>
</li>
<li><p>Data synchronization or backup tasks</p>
</li>
<li><p>Multiple containers that <strong>must</strong> be together.</p>
</li>
<li><p>Often used in the <strong>Sidecar Pattern</strong>:</p>
<ul>
<li><p><strong>Main app container</strong> (your application)</p>
</li>
<li><p><strong>Helper container</strong> (e.g., log collector, proxy)</p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-plaintext">apiVersion: v1
kind: Pod
metadata:
  name: my-multi-container-pod
spec:
  containers:
    - name: app-container
      image: myapp:latest
      ports:
        - containerPort: 8080   # App listens on 8080
    - name: log-collector
      image: fluentd:latest
</code></pre>
<hr />
<h2 id="heading-5-pod-to-pod-communication">5. Pod-to-Pod Communication</h2>
<ul>
<li><p><strong>Same Node:</strong><br />  Pods talk directly via their IPs no extra steps.</p>
</li>
<li><p><strong>Different Nodes:</strong><br />  Kubernetes uses a <strong>Cluster Network</strong> (e.g., Calico, Flannel, Cilium) to make sure pods can talk to each other even if they’re far apart in different machines.</p>
</li>
</ul>
<hr />
<h2 id="heading-6-pod-storage">6. Pod Storage</h2>
<p>Containers are <strong>ephemeral</strong> if they restart, data inside disappears.<br /><strong>Solution:</strong> Use <strong>Volumes</strong>.</p>
<h3 id="heading-common-volume-types">Common Volume Types:</h3>
<ul>
<li><p><code>emptyDir</code> – Temporary storage; gone when the pod stops.</p>
</li>
<li><p><code>hostPath</code> – Uses a folder from the host machine.</p>
</li>
<li><p><strong>Persistent Volume (PV)</strong> – Storage that stays even if the pod is deleted.</p>
</li>
</ul>
<p><strong>Tip:</strong> For databases or apps that store important data, always use <strong>Persistent Volumes</strong>.</p>
<hr />
<h2 id="heading-7-pod-lifecycle">7. Pod Lifecycle</h2>
<p><img src="https://sdmntprnorthcentralus.oaiusercontent.com/files/00000000-3ee4-622f-985e-21e7f08aefb0/raw?se=2025-08-15T18%3A20%3A17Z&amp;sp=r&amp;sv=2024-08-04&amp;sr=b&amp;scid=78364f94-bb03-50df-b101-d8674363341d&amp;skoid=bbd22fc4-f881-4ea4-b2f3-c12033cf6a8b&amp;sktid=a48cca56-e6da-484e-a814-9c849652bcb3&amp;skt=2025-08-15T01%3A27%3A34Z&amp;ske=2025-08-16T01%3A27%3A34Z&amp;sks=b&amp;skv=2024-08-04&amp;sig=lf2Zp4U2q9nkop%2BH8l%2BkCmhPAkiCRP4f4PJr2mQtBAg%3D" alt /></p>
<h3 id="heading-1-pending"><strong>1. Pending</strong></h3>
<p>Pod is created but not yet scheduled or started.<br /><strong>Possible scenarios:</strong></p>
<ul>
<li><p>No node has enough <strong>CPU</strong> or <strong>memory</strong> to host the pod.</p>
</li>
<li><p>Required <strong>Persistent Volume (PV)</strong> is not yet bound.</p>
</li>
<li><p>Container image is still <strong>downloading</strong> from the registry.</p>
</li>
<li><p>Scheduling constraints (e.g., <strong>nodeSelector</strong>, <strong>taints/tolerations</strong>) prevent placement.</p>
</li>
</ul>
<h3 id="heading-2-running"><strong>2. Running</strong></h3>
<p>Pod has been scheduled to a node, and at least one container is running without issues.<br /><strong>Possible scenarios:</strong></p>
<ul>
<li><p>Application is <strong>healthy</strong> and serving traffic normally.</p>
</li>
<li><p>Containers have passed readiness/liveness probes.</p>
</li>
</ul>
<h3 id="heading-3-succeeded"><strong>3. Succeeded</strong></h3>
<p>All containers in the pod have completed successfully and will not restart.<br /><strong>Possible scenarios:</strong></p>
<ul>
<li><p><strong>Batch job</strong> finished processing data with no errors.</p>
</li>
<li><p><strong>One-off scripts</strong> executed to completion.</p>
</li>
</ul>
<h3 id="heading-4-failed"><strong>4. Failed</strong></h3>
<p>All containers have stopped, and at least one exited with a <strong>non-zero status</strong>.<br /><strong>Possible scenarios:</strong></p>
<ul>
<li><p>Wrong <strong>command or arguments</strong> in the container entrypoint.</p>
</li>
<li><p>Application crashed due to <strong>missing files</strong> or <strong>misconfiguration</strong>.</p>
</li>
<li><p>Required services or dependencies were <strong>unavailable</strong>.</p>
</li>
</ul>
<h3 id="heading-5-crashloopbackoff"><strong>5. CrashLoopBackOff</strong></h3>
<p>Pod repeatedly fails, Kubernetes restarts it, but it keeps crashing.<br /><strong>Possible scenarios:</strong></p>
<ul>
<li><p>Invalid <strong>credentials</strong> (e.g., DB connection fails due to wrong username/password).</p>
</li>
<li><p>Missing <strong>configMap</strong> or <strong>secret</strong>.</p>
</li>
<li><p><strong>Port conflict</strong> (port already in use).</p>
</li>
<li><p>Application <strong>bug</strong> causing repeated crashes.</p>
</li>
<li><p><strong>Out of Memory (OOMKilled)</strong> due to insufficient resources.</p>
</li>
</ul>
<h3 id="heading-6-unknown"><strong>6. Unknown</strong></h3>
<p>Pod state can’t be determined because the Kubernetes API server has lost communication with the node where the pod was running.</p>
<p><strong>Possible scenarios:</strong></p>
<ul>
<li><p>Node is <strong>unreachable</strong> (network failure or shutdown).</p>
</li>
<li><p><strong>Kubelet crash</strong> or kubelet is heavily <strong>overloaded</strong> and not reporting status.</p>
</li>
<li><p><strong>Cloud node deleted/stopped</strong> (e.g., in AWS, GCP, or Azure).</p>
</li>
</ul>
<hr />
<h2 id="heading-8-deploying-pods">8. Deploying Pods</h2>
<p>You can create a pod directly, but in real-world projects, you usually use <strong>controllers</strong>:</p>
<ul>
<li><p><strong>Deployment</strong> – For apps that can have many copies (stateless).</p>
</li>
<li><p><strong>StatefulSet</strong> – For apps that need a fixed identity (databases).</p>
</li>
<li><p><strong>DaemonSet</strong> – Runs one copy of a pod on every node.</p>
</li>
</ul>
<p><strong>Example Pod:</strong></p>
<hr />
<h2 id="heading-9-best-practices">9. Best Practices</h2>
<ul>
<li><p><strong>Don’t</strong> run pods manually in production use Deployments/StatefulSets.</p>
</li>
<li><p>Add <strong>liveness</strong> and <strong>readiness</strong> probes to check health.</p>
</li>
<li><p>Keep pods <strong>small</strong> only related containers inside.</p>
</li>
<li><p>Set <strong>resource limits</strong> (CPU, memory).</p>
</li>
<li><p>Design apps to <strong>handle restarts</strong>.</p>
</li>
</ul>
<hr />
<h2 id="heading-10-summary">10. Summary</h2>
<ul>
<li><p>Pods = smallest deployable units in Kubernetes.</p>
</li>
<li><p>They wrap one or more containers with shared networking/storage.</p>
</li>
<li><p>Communication is handled by Kubernetes networking.</p>
</li>
<li><p>Volumes keep data safe beyond container restarts.</p>
</li>
</ul>
<h2 id="heading-11-kubernetes-pod-commands-with-explanation">11. Kubernetes Pod Commands with Explanation</h2>
<p><strong>1. Create Pod</strong></p>
<pre><code class="lang-plaintext">kubectl apply -f pod.yaml
</code></pre>
<ul>
<li><p>This creates a Pod using the <strong>YAML configuration file</strong> (<code>pod.yaml</code>).</p>
</li>
<li><p>The YAML file defines what container image, ports, and volumes the Pod should use.</p>
</li>
<li><p>If the Pod already exists, this command will <strong>update</strong> it.</p>
</li>
</ul>
<hr />
<p><strong>2. Get Pods</strong></p>
<pre><code class="lang-plaintext">kubectl get pods
kubectl get pods -o wide
</code></pre>
<ul>
<li><p>Shows all Pods in the current <strong>namespace</strong>.</p>
</li>
<li><p><code>kubectl get pods</code> → Basic info (Pod name, status, age, restarts).</p>
</li>
<li><p><code>kubectl get pods -o wide</code> → Extra details like <strong>Node name, Pod IP, container image</strong> etc.</p>
</li>
</ul>
<hr />
<p><strong>3. Describe Pod</strong></p>
<pre><code class="lang-plaintext">kubectl describe pod &lt;pod-name&gt;
</code></pre>
<ul>
<li><p>Gives <strong>detailed information</strong> about a Pod:</p>
</li>
<li><p>Which <strong>node</strong> it is running on.</p>
</li>
<li><p>What <strong>containers</strong> are inside.</p>
</li>
<li><p>Events (like scheduling, pulling image, errors).</p>
</li>
<li><p>Resource requests &amp; limits :useful for <strong>debugging why a Pod is failing</strong> or stuck in Pending/CrashLoopBackOff.</p>
</li>
</ul>
<hr />
<p><strong>4. Check Logs</strong></p>
<pre><code class="lang-plaintext">kubectl logs &lt;pod-name&gt;
kubectl logs &lt;pod-name&gt; -c &lt;container-name&gt;
</code></pre>
<ul>
<li><p>Shows logs generated by containers inside the Pod.</p>
</li>
<li><p>For <strong>single-container Pods</strong>, just use Pod name.</p>
</li>
<li><p>For <strong>multi-container Pods</strong>, add <code>-c &lt;container-name&gt;</code> to specify which container’s logs you want. Useful for checking <strong>application errors</strong> or <strong>runtime issues</strong>.</p>
</li>
</ul>
<hr />
<p><strong>5. Enter into Pod (exec)</strong></p>
<pre><code class="lang-plaintext">kubectl exec -it &lt;pod-name&gt; -- /bin/bash
kubectl exec -it &lt;pod-name&gt; -c &lt;container-name&gt; -- /bin/bash
</code></pre>
<ul>
<li><p>Opens an <strong>interactive shell inside a Pod’s container</strong>.</p>
</li>
<li><p><code>-it</code> → interactive mode (so you can type commands).</p>
</li>
<li><p><code>/bin/bash</code> (or <code>/bin/sh</code>) → type of shell.<br />  Useful for <strong>debugging inside the container</strong> (checking files, logs, configs).</p>
</li>
</ul>
<hr />
<p><strong>6. Delete Pod</strong></p>
<pre><code class="lang-plaintext">kubectl delete pod &lt;pod-name&gt;
kubectl delete -f pod.yaml
</code></pre>
<ul>
<li><p><code>kubectl delete pod &lt;pod-name&gt;</code> → remove Pod directly.</p>
</li>
<li><p><code>kubectl delete -f pod.yaml</code> → remove Pod defined in YAML file.</p>
</li>
<li><p><strong>Note:</strong> If the Pod was created by a <strong>Deployment/ReplicaSet</strong>, Kubernetes will <strong>automatically recreate</strong> it.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>