- Published on
Use Podman to Create and Work with Virtual Machines
- Authors
- Name
- AbnAsia.org
- @steven_n_t
"When you think of Red Hat's Podman, one thing comes to mind: containers. That's because Podman was created as a tool for creating and managing containerized applications and services.
But Podman has another trick up its sleeve. With the help of the QEMU emulator, Podman is capable of creating a basic Fedora CoreOS virtual machine that can be used for containers, containerized workloads or for the development of such containerized applications (so long as they work within the realm of Fedora CoreOS).
For those who aren't familiar with Fedora CoreOS, it was created specifically to be optimized to run containerized applications. Fedora CoreOS was initially released on Nov. 6, 2003, and has been steadily growing since. As the name implies, Fedora CoreOS is kept to a bare minimum by design, so it only has what you need.
Podman makes deploying Fedora CoreOS virtual machines a breeze. By doing this, you don't have to worry about pulling down the latest version of Fedora CoreOS from Docker Hub or any other third-party repository. That means the virtual machines are clean.
But how do you start working with these virtual machines? Let me show you how.
What You'll Need
To work with Podman Machines, you'll want to have a Ubuntu-based Linux distribution. Although the version of Podman on RHEL-based distributions supports the Machines command, it's not currently possible to install the necessary QEMU software to make it work. That's why I'm going to focus my demonstration on Ubuntu. You'll also need a user with sudo privileges for the installation.
That's it. Let's make some VM magic.
Installing Podman and the Requirements
Ubuntu doesn't ship with Podman installed. The good news is that it can be installed from the standard repositories. So log into your Ubuntu system, open a terminal window, and install Podman with the command:
sudo apt-get install podman -y
You'll be prompted for your user password in order to gain admin privileges. Once that installation is complete, you'll then need to install the required QEMU software, which is accomplished with the command:
sudo apt-get install qemu-system -y
When that completes, there's one (or two) more step(s) you must take. First, download the gvproxy file and save it to the proper location with the command:
sudo wget https://github.com/containers/gvisor-tap-vsock/releases/download/v0.6.2/gvproxy-linux -O /usr/libexec/podman/gvproxy && sudo chmod +x /usr/libexec/podman/gvproxy
Finally, you need to make sure the KVM kernel module is loaded, which means the machine you're running on must support KVM. This can be done with one of the following:
sudo modprobe kvm-intel
sudo modprobe kvm-amd
You're now ready to move on to creating your first Fedora CoreOS virtual machine.
Deploying a Virtual Machine
Podman virtual machines are managed with the podman machine command (along with various options). First, view the current machines with the command: podman machine list
You shouldn't see any virtual machines listed because we haven't created any. To create your first VM, you initialize it with the command: podman machine init
The above command will create a new VM with a randomly generated name. You can also generate one with a user-specified name like this:
podman machine init NAME
Where NAME is the name of the machine you want to deploy.
Now, if you view the available VMs (with the command podman machine list), you should see one listed, either with a randomly generated or user-created name.
Let's say you created a new VM called vm1. To start that machine, issue the command:
podman machine start vm1
The virtual machine will start, and when you receive your prompt back, you're ready to go.
SSH into Your Virtual Machine
With the virtual machine running, it's now time to access it, which is done via SSH. Before you try to run the standard ssh command, that's not how it works in this case. To SSH into your virtual machine, you run the command:
podman machine ssh NAME
Where NAME is the name of the virtual machine. If you didn't supply a name when you created the VM, you could simply issue the command:
podman machine ssh
At this point, you'll find yourself inside the running virtual machine, where you can start developing your containerized application. When you're finished, you can exit from the machine with the command:
exit
Finally, you can stop the virtual machine with the command:
podman machine stop
Of course, if you gave the VM a custom name, that command would be:
podman machine stop NAME
Where NAME is the name of the machine you wish to stop.
You can deploy as many virtual machines as you like. I would recommend, however, that you always give your VM a unique identifying name to indicate the containerized app or service you're building.
You can also delete a VM with the command:
podman machine rm NAME
Where NAME is the name of the VM you wish to delete.
And that is all there is to deploying virtual machines with the Podman application."
Author
AiUTOMATING PEOPLE, ABN ASIA was founded by people with deep roots in academia, with work experience in the US, Holland, Hungary, Japan, South Korea, Singapore, and Vietnam. ABN Asia is where academia and technology meet opportunity. With our cutting-edge solutions and competent software development services, we're helping businesses level up and take on the global scene. Our commitment: Faster. Better. More reliable. In most cases: Cheaper as well.
Feel free to reach out to us whenever you require IT services, digital consulting, off-the-shelf software solutions, or if you'd like to send us requests for proposals (RFPs). You can contact us at [email protected]. We're ready to assist you with all your technology needs.
© ABN ASIA