Module 9 Lesson 3: Managing Pods with Podman
·DevOps

Module 9 Lesson 3: Managing Pods with Podman

Think like Kubernetes. Learn how to use Podman to group related containers into 'Pods', allowing them to share resources and network namespaces like a production cluster.

Module 9 Lesson 3: Managing Pods with Podman

While Docker focuses on Containers, Podman focuses on Pods. A Pod is a group of one or more containers that share the same network, storage, and lifecycle.

1. Why use a Pod?

If you have a Python app and a database that ONLY work together, it makes sense to group them.

  • Shared Network: Containers in a Pod talk to each other using localhost. There is no need for complex bridge networking!
  • Single IP: The Pod has one IP address on your network.
  • Co-location: In a cluster, the orchestrator is guaranteed to run both containers on the same physical server.

2. Creating a Pod with Podman

# 1. Create the empty Pod
podman pod create --name my-app-stack -p 8080:80

# 2. Add the database to the Pod
podman run -d --pod my-app-stack --name db postgres

# 3. Add the web-app to the Pod
podman run -d --pod my-app-stack --name web my-python-app

The Localhost Magic: In your Python app code, you can connect to the database using the URL localhost:5432. Because they are in the same Pod, they share the same "Loopback" interface.


3. Podman and Kubernetes YAML

One of Podman's coolest features is that it can generate Kubernetes-compatible YAML files from your running Pods.

podman generate kube my-app-stack > deployment.yaml

You can now take this deployment.yaml and run it on a massive AWS or Google Cloud Kubernetes cluster. Podman is the perfect "Bridge" between your laptop and the enterprise cloud.


4. Comparing Pods and Compose

  • Docker Compose: Best for manual multi-container development on a single machine.
  • Podman Pods: Best for preparing for Kubernetes and grouped resource management.

Exercise: The Localhost Connection

  1. Create a pod named test-pod and map host port 8081 to 80.
  2. Add an nginx container to the pod.
  3. Add an alpine container to the same pod.
  4. exec into the alpine container and try to curl localhost:80.
  5. Did it work? Why is this easier than setting up a virtual network?
  6. Research: In a Podman Pod, what is the "Infra Container"? (Hint: It’s the container that "holds" the network alive).

Summary

Pods are the next step in the evolution of containerization. By grouping related containers together, you simplify your networking and prepare your application for the world of Kubernetes.

Next Module: Beyond a single host: Module 10: Orchestration and Pods.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn