TechyPilots Info
TechyPilots.INFO
Home/Tutorials/Kubernetes/Understanding Kubernetes Pods
Kubernetes Tutorial

Understanding Kubernetes Pods

Learn what Kubernetes Pods are, how they run containers, how Pod networking and storage work, understand the Pod lifecycle, create Pods using YAML, and manage workloads using Kubernetes.

Level: Beginner
Topic: Kubernetes Fundamentals

Kubernetes Architecture

The Smallest Deployable Unit

Pods and Containers

Shared Networking

Shared Storage

Pod Lifecycle

Multi-Container Pods

Introduction

What is a Kubernetes Pod?

A Pod is the smallest deployable unit in Kubernetes. A Pod represents one or more containers that run together as a single unit on a Kubernetes node.

Kubernetes does not normally schedule individual containers directly. Instead, containers are grouped inside Pods, which provide shared networking, shared storage, and a common execution environment.

Most applications use one main container per Pod, but multi-container Pods can also be useful when containers need to work closely together.

Pod Fundamentals

Understanding how Pods work

Pods provide the environment where containers run and interact with Kubernetes resources.

01

Smallest Deployable Unit

A Pod is the smallest deployable object in Kubernetes. Kubernetes schedules and manages Pods rather than individual containers.

Key Topics

  • Pod abstraction
  • Container grouping
  • Scheduling
  • Workloads
02

Shared Networking

Containers inside the same Pod share networking resources and can communicate with each other using localhost.

Key Topics

  • Shared IP address
  • localhost communication
  • Shared ports
  • Network namespace
03

Shared Storage

Containers inside a Pod can share storage by mounting the same Kubernetes Volume.

Key Topics

  • Volumes
  • Shared data
  • Container storage
  • Persistent storage
04

Pod Lifecycle

Pods move through different lifecycle phases depending on their creation, execution, completion, or failure.

Key Topics

  • Pending
  • Running
  • Succeeded
  • Failed

Pod Architecture

Components of a Kubernetes Pod

A Pod can contain containers, networking configuration, storage, application configuration, and resource requirements.

Pod

The Kubernetes object that represents one or more containers running together.

Containers

The application processes that run inside the Pod.

Networking

Containers in the Pod share the same network identity and IP address.

Volumes

Storage resources that can be mounted and shared by containers.

Configuration

Environment variables, ConfigMaps, Secrets, and other runtime settings.

Resources

CPU and memory requests and limits used to manage workload resources.

YAML Configuration

Creating your first Pod

Kubernetes resources are commonly defined using YAML manifests. The manifest describes the desired state of the Pod.

A basic Pod configuration includes the API version, resource type, metadata, and the specification for the containers that should run inside the Pod.

Basic Pod Example

apiVersion: v1
kind: Pod

metadata:
  name: nginx-pod

spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80

Deploying Pods

Apply the Pod configuration

After creating a YAML file, you can submit the configuration to the Kubernetes API using kubectl.

Kubernetes will schedule the Pod to an appropriate node based on available resources, scheduling rules, and other cluster configuration.

Create the Pod

kubectl apply -f pod.yaml

kubectl get pods

kubectl describe pod nginx-pod

Networking

How Pod networking works

Each Pod receives its own network identity. Containers inside the same Pod share the same network namespace.

This means containers in the same Pod can communicate with each other using localhost while sharing the same IP address.

Communication between different Pods is handled through the Kubernetes networking model and can be exposed using Services.

Pod

Shared Pod IP Address

Container A

localhost

Container B

localhost

Storage

Sharing data with Volumes

Containers normally have their own filesystem environments, but Kubernetes Volumes can provide shared storage between containers inside the same Pod.

Volumes can also be used to provide configuration, temporary storage, or persistent application data depending on the workload requirements.

Shared Volume Example

spec:
  containers:
    - name: app
      image: nginx
      volumeMounts:
        - name: shared-data
          mountPath: /data

  volumes:
    - name: shared-data
      emptyDir: {}

Multi-Container Pods

Running multiple containers together

A Pod can run multiple containers when those containers are tightly coupled and need to share networking or storage.

A common example is a main application container combined with a helper container that performs logging, monitoring, proxying, or other supporting tasks.

Containers that have independent lifecycles are often better deployed as separate Pods and connected through Kubernetes networking.

Multi-Container Pod Example

apiVersion: v1
kind: Pod

metadata:
  name: multi-container-pod

spec:
  containers:
    - name: application
      image: nginx

    - name: helper
      image: busybox
      command:
        - sh
        - -c
        - "while true; do sleep 30; done"

Pod Lifecycle

Understanding Pod phases

Kubernetes tracks the overall state of a Pod using lifecycle phases.

Pending

The Pod has been accepted by Kubernetes, but one or more containers have not yet started.

Running

The Pod has been scheduled and at least one container is running or starting.

Succeeded

All containers have completed successfully and will not be restarted.

Failed

One or more containers terminated unsuccessfully.

Unknown

Kubernetes cannot determine the current state of the Pod.

Workload Management

Why Pods are usually managed by controllers

Individual Pods are useful for learning and testing, but production applications are normally managed using Kubernetes workload controllers.

Controllers such as Deployments help maintain the desired number of Pod replicas and can create replacement Pods when existing Pods fail or are terminated.

This allows Kubernetes to manage application availability and updates more effectively than manually creating individual Pods.

Deployment

Manages ReplicaSets and application updates.

ReplicaSet

Helps maintain the desired number of Pod replicas.

Pods

Run the application containers.

kubectl

Useful Pod commands

Use these kubectl commands to create, inspect, troubleshoot, and manage Pods.

kubectl get pods

List Pods in the current namespace.

kubectl get pods -o wide

List Pods with additional details such as node and IP address.

kubectl describe pod <pod-name>

Display detailed information about a Pod.

kubectl logs <pod-name>

View logs from a container in a Pod.

kubectl exec -it <pod-name> -- sh

Open an interactive shell inside a container.

kubectl delete pod <pod-name>

Delete a Pod from the cluster.

kubectl apply -f pod.yaml

Create or update a Pod using a YAML manifest.

kubectl get pods --watch

Continuously watch changes to Pod status.

Learning Roadmap

How to learn Kubernetes Pods

Follow these steps to understand how Pods work and how they fit into the Kubernetes ecosystem.

Step 1

Understand the Pod Concept

Learn why Kubernetes uses Pods as the smallest deployable unit instead of managing individual containers directly.

Step 2

Create Your First Pod

Create a simple Pod using a YAML manifest and deploy it to a Kubernetes cluster.

Step 3

Inspect Pod Status

Use kubectl commands to check Pod status, events, networking, and container information.

Step 4

Learn Pod Networking

Understand how containers inside the same Pod share an IP address and communicate using localhost.

Step 5

Explore Multi-Container Pods

Learn when multiple tightly coupled containers can run together inside the same Pod.

Step 6

Manage Pods with Controllers

Learn why Deployments and other workload controllers are normally used to manage Pods in production.

Best Practices

Kubernetes Pod best practices

Use Controllers

Use Deployments and other workload controllers instead of manually managing individual Pods for most production workloads.

Define Resource Requests

Specify appropriate CPU and memory requests to help Kubernetes schedule workloads effectively.

Set Resource Limits

Use resource limits where appropriate to prevent workloads from consuming excessive cluster resources.

Keep Containers Focused

Use one primary responsibility per container and use multi-container Pods only when containers are tightly coupled.

Use Health Checks

Configure readiness and liveness probes to help Kubernetes understand application health.

Avoid Unnecessary Privileges

Run containers with only the permissions and access required for their workloads.

Next Step

Start working with Kubernetes Pods

Practice creating Pods, inspecting their status, checking logs, understanding networking, and deploying workloads using Kubernetes controllers.