E-books

Podman in Action (Early access)

Daniel Walsh
September 8, 2022
Podman in Action e-book cover

About

Dive into Podman, the next-generation container engine that manages containers rootlessly. Podman is an excellent tool for developers looking to containerize their applications securely because it provides extra layers of security unavailable in Docker and other container platforms.

Podman in Action introduces Podman’s features and capabilities, including how to work with containers, build container images, and convert containerized applications into either single-node services to run on edge devices or Kubernetes-based microservices. It discusses Podman’s unique advantages over Docker and shows how you can easily migrate your Docker-based infrastructure. 

Written by Daniel Walsh, who leads the Podman team at Red Hat, this book contains easy-to-follow examples to help you learn Podman quickly, including steps to deploy a complete containerized web service.

Download Podman in Action and learn how to:

  • Build and run containers in rootless mode
  • Develop and manage pods
  • Use systemd to oversee a container’s life cycle
  • Work with the Podman service via Python
  • Keep your containers confined using Podman security features
  • Manage containerized applications on edge devices

Note: This preview edition of Podman in Action is available through the Manning Early Access Program, which gives you early access to books as they’re being created. This download contains includes chapters 1-11 and appendices A-F. The final book is estimated to be released in November 2022.

Excerpt

The Kubernetes YAML file is the object used to launch pods and containers within Kubernetes. In chapter 5 you learned the configuration files used by Podman are written using TOML, which is very similar to YAML. Both configuration languages are attempting to be human-readable. YAML relies on indenting substanzas which is different syntax then you learned with TOML. You can go to the https://yaml.org/ web site to learn more about the language.

If you are going to work a lot with Kubernetes YAML files, it is nice to have a text editor or IDE, like Visual Studio and vscode, that can at least understand YAML, even better if it knows the Kubernetes language. Kubernetes YAML is descriptive and powerful. It allows you to model the desired state or your application in a declarative language. As we stated in the introduction to this chapter, writing these YAML files is a barrier for developers to get through when moving their containers from a local system to Kubernetes. Most developers just web search an existing Kubernetes.yaml file and then begin cutting and pasting their container command, image and options into the yaml file. While this works, it can lead to unintended consequences, and often unnecessary work. Scott McCarty, product manager of Podman, tossed out an idea: “What I would really like to do is help users get from Podman to orchestrating their containers with Kubernetes.” This led the Podman developers to create a new Podman command podman generate kube.

Generating Kubernetes YAML files with Podman

Imagine you want to take the containers you generated in the previous chapters and run them within Kubernetes. You need to write the Kubernetes YAML file to make this happen. Where do you start?

You are going to learn a new command, podman generate kube. This Podman command captures the description of local pods and containers and then translates them into Kubernetes YAML. This helps you transition to a more sophisticated orchestration environment like Kubernetes. The generated Kubernetes YAML file can then be used by Kubernetes commands to launch your pods and containers into a Kubernetes cluster.

You can recreate the containers/pods locally using Podman on the command line using the same Podman run, create, stop commands you have learned in the previous chapters. Using the following commands, re-create the container you have been working with.

First remove the container if it exists using podman rm. Notice I introduce a new flag –– ignore, which tells the podman rm command not to report errors when the container does not exist. Then recreate the container from the command line.

$ podman rm -f --ignore myapp

$ podman create -p 8080:8080 --name myapp quay.io/rhatdan/myimage

9305822e6089ca28a1fdbb005c12f57f4a26be273fe5d49a1908eadbcfdcb7d4

Now use the command podman generate kube myapp to generate the Kubernetes YAML file. Podman inspects the existing container or pod in its database for all of the fields required to run the container in Kubernetes and then populates them in the Kubernetes YAML file.

$ podman generate kube myapp > myapp.yaml

Comments