0Pricing
Docker & DevOps Fundamentals · Lesson

Pods: The Smallest Units

Learn about Pods, the fundamental building blocks in Kubernetes, and how to define and manage them.

Pods: The Smallest Units is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What is a Kubernetes Pod?

In Kubernetes, the smallest and most fundamental unit you can deploy is a Pod. Think of a Pod as a single 'house' that holds one or more containers.

Pods are an abstraction over containers. They represent a running process in your cluster and encapsulate application containers, storage resources, unique network IP, and options that govern how containers should run.

Pods: The Smallest Units — illustration 1

Pod vs. Container: The Difference

You might wonder, 'Why do I need a Pod if I already have containers?' Here's the key difference:

  • A Container (like a Docker container) is a package of an application and its dependencies.
  • A Pod is the Kubernetes abstraction that wraps one or more containers, providing them with shared resources and a single network identity.

While a container is the actual executable, a Pod is how Kubernetes manages and orchestrates those executables.

Why Use Pods?

Pods offer several crucial benefits:

  • Shared Network Namespace: All containers within a Pod share the same IP address and network ports. They can communicate with each other using localhost.
  • Shared Storage: Pods can share storage volumes, allowing containers within the same Pod to access common data.
  • Co-location & Co-scheduling: Containers that need to work closely together (e.g., an application and a logging agent) can be guaranteed to run on the same node and are always scheduled together.

Anatomy of a Pod Definition

Pods are defined using YAML configuration files. Here are the core components you'll find:

  • apiVersion: Specifies the Kubernetes API version (e.g., v1).
  • kind: The type of Kubernetes object, which is Pod.
  • metadata: Information like the Pod's name and labels.
  • spec: The desired state for the Pod, including the containers to run, volumes, and other settings.

Defining a Single-Container Pod

Most Pods contain a single container. This is common for simple applications. Here's a basic YAML definition for a Pod running an Nginx web server:

apiVersion: v1
kind: Pod
metadata:
  name: my-nginx-pod
  labels:
    app: webserver
spec:
  containers:
  - name: nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80

Deploying Your First Pod

To create a Pod from a YAML file, you use the kubectl apply command. This tells Kubernetes to create or update resources based on your definition.

Let's say you save the previous Nginx Pod definition as nginx-pod.yaml. You would deploy it like this:

  • kubectl apply -f nginx-pod.yaml

Kubernetes will then schedule this Pod to run on one of its worker nodes.

Inspecting Pods: Get & Describe

Once deployed, you'll want to check the status of your Pods. Here are two essential kubectl commands:

  • kubectl get pods: Lists all Pods in the current namespace, showing their name, status, and node.
  • kubectl describe pod <pod-name>: Provides detailed information about a specific Pod, including events, container status, and assigned resources.

These commands are vital for monitoring and troubleshooting.

Multi-Container Pods: Sidecars

While single-container Pods are common, some scenarios benefit from multi-container Pods. A classic example is the Sidecar Pattern.

A sidecar container runs alongside your main application container in the same Pod, performing auxiliary tasks like:

  • Logging and monitoring agents
  • Data synchronization
  • Proxying network traffic

They share the Pod's network and storage, making communication efficient.

Example: Multi-Container Pod

Here's an example of a multi-container Pod. It has an Nginx web server and a busybox sidecar container that writes logs to a shared volume.

apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  volumes:
  - name: shared-log-volume
    emptyDir: {}
  containers:
  - name: web-server
    image: nginx:latest
    ports:
    - containerPort: 80
    volumeMounts:
    - name: shared-log-volume
      mountPath: /var/log/nginx
  - name: log-writer
    image: busybox:latest
    command: ["/bin/sh", "-c", "while true; do echo 'Hello from sidecar!' >> /var/log/app.log; sleep 5; done"]
    volumeMounts:
    - name: shared-log-volume
      mountPath: /var/log/app

Check Your Pod Knowledge

Which of the following statements about Kubernetes Pods is TRUE?

Recap: Pods - The Core Unit

You've just learned about Kubernetes Pods, the fundamental building blocks of your applications in a cluster.

  • Pods encapsulate one or more containers, providing them with shared resources.
  • They offer shared network, storage, and guarantee co-location for related containers.
  • You define Pods using YAML and deploy them with kubectl apply.
  • kubectl get pods and kubectl describe pod help you monitor them.

Next, we'll explore more kubectl commands for interacting with your cluster!

Frequently asked questions

Is the “Pods: The Smallest Units” lesson free?

Yes — the full text of “Pods: The Smallest Units” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Pods: The Smallest Units”?

Learn about Pods, the fundamental building blocks in Kubernetes, and how to define and manage them. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Docker & DevOps Fundamentals?

No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Pods: The Smallest Units” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Docker & DevOps Fundamentals lesson?

Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Kubernetes Architecture
  2. Pods: The Smallest Units
  3. kubectl Commands Essentials
  4. Namespaces and Labels for Organization
← Back to Docker & DevOps Fundamentals