2. Using Podman and Minikube - jbellver99/minikube-podman Wiki

Note
The development of this solution has moved to devonfw-forge/podman-minikube.
This repository will remain available some time to avoid broken links.

The goal of this section is to give you the basics of Podman and Minikube, providing some links at the end if you desire to go further with them.

Podman cannot directly run on Windows, that is why we will be using Minikube, which provides an underlying Linux Virtual Machine running Podman, and we will be using Podman remote client in our local Windows machine to launch commands that will then be executed in the VM transparently.

2.1 Minikube

"Minikube is a tool which enables you to run Kubernetes locally. It runs a single-node Kubernetes cluster on your computer".

Useful commands:

  • minikube start Starts a fresh local Minikube Kubernetes cluster on your machine.

  • minikube stop Safely stops Minikube, and deletes any image loaded and any container running on Podman, so do not execute this command unless there is a reason to do so. You can restart your computer without stopping Minikube and everything will remain there after reboot.

Caution
If you minikube stop and then minikube start, the IP of the VM will change, in this case you will need to launch a new Powershell window or reload profile with & $PROFILE.
Caution
Sometimes, if you minikube stop with some containers still running, when you minikube start, you may get errors saying that the name of the container is already in use, but that container name will not exist if you try to delete it. Avoid stopping without first removing containers.
  • minikube pause Leaves Kubernetes in pause, but the VM will continue running. If you just need Podman, we advice you to use this command to improve performance. (After test, around 60 MB of memory are saved)

  • minikube delete Deletes the existing cluster

You can check minikube --help for more information on commands.

We also created custom commands to save all images or load them at the start, in case you need to use minikube stop, but loosing images is a no-go:

  • minikube_save_images Saves all images as .tar files in a temporal directory. This command accepts -s flag, which runs minikube stop after saving images.

  • minikube_load_images Loads all the images from the .tar files generated by minikube_save_images on the VM, then deletes .tar files loaded successfully. This command accepts -s flag, which runs minikube start before loading images.

2.2 How to use Podman

You can use Podman commands from any Powershell prompt, just as with Docker. Moreover, you can continue using docker <command> as it has been aliased as part of the installation.

The vast majority of Docker commands will continue working as expected. Also, Podman is capable of using Dockerfiles to build images.

Quick example

In order to build an image and run a container bases on that image, follow these steps:

  1. Create the Dockerfile with the recipe to build your image. In this example we assume it is a web application that exposes some port.

  2. Open a Powershell window where your Dockerfile is located.

  3. Run podman build -t <image tag> .. If you want to then push it to a remote repository, the tag should look like <user>/<repository>:<tag>.

  4. Run podman push <image tag> --creds <user>:<password> (Optional, only required if you want to push your image to a remote repository). It uses Docker Hub as default remote.

  5. Run the container with podman run --name <container name> <image tag> -d -p <container port>:<VM port>.

  6. You can check your container is running with podman ps.

  7. To access your web app, run minikube ip in order to know the Minikube VM IP, then access <VM IP>:<VM port> in your web browser.

  8. Finally, to stop, start and delete your container, you just need to:

    • podman stop <container name>

    • podman start <container name>

    • podman rm <container name>

Sharing volumes

With Docker you can mount a local directory as a volume on a container adding -v <local path>:<container path> when using docker run.

With Podman, this is essentially the same, but since Podman is running inside the Minikube VM, you have to first mount the local path on the VM using:

minikube mount <local path>:<VM path>

Note
This will start a process on your current PowerShell window. As long as the process is kept running, the volume will be shared.

Then you can use the podman run command as expected with the -v flag, taking care of specifying the above used VM path:

podman run --name <container name> <image tag> -v <VM path>:<container path>

Tip
You can use /mnt/your_desired_path as VM path.

2.3 Podman-compose

Podman 2 does not integrate a way of launching interdependent containers. While Podman 3 comes to Minikube, which natively supports docker-compose files, we have developed a solution based on podman-compose, that is installed along with Minikube. This solution reads docker-compose files and creates a pod grouping the different containers.

"Pods are a way of grouping containers together inside their own namespace, network and security context".

Using podman-compose is as simple as running podman-compose [optionals flags] up on the directory where your docker-compose.yml file is, probably using -m flag (described below).

Flags

  • -m Starts sharing a volume with the VM in a background Powershell window. This is mandatory to make podman-compose work correctly, but you do not need to use the flag each time as long as you do not close the aforementioned window, which will be kept after the execution of podman-compose so to sabe time (sharing the volume is a bit slow).

Note
The paths internally mounted are C:\Users\%USERNAME%\tmp_share_windows (local) and /tmp_shared_VM (VM), in case you need to dig on them.
  • -u Remounts volume mounted by -m flag. Useful in case you start seeing Input/Output error after some podman-compose usage.

Warning
Make sure the Powershell window sharing the volume is closed before using -u flag.
  • -f <file> If the declaration file of your stack is not named docker-compose.yml use this flag to give the name of the file.

2.4 Differences with Docker

  • No GUI as in Docker Desktop.

  • podman-compose only supports the equivalent to docker-compose up.

  • No Docker Swarm. Use Kubernetes.

  • You can manage pods with Podman, not just containers.

2.5 Using Podman with a VPN

We are working in a solution for being able to use Podman while being connected to a Cisco AnyConnect VPN. No ETA yet.

Other VPNs might work, though.

2.6 Updating the scripts

To update the scripts we have created around Podman/Minikube and get the latest features and bug fixes, pull the latest version of this repository and run update.cmd.

2.7 Uninstall

To remove our scripts from your computer run %APPDATA%\podman-2.2.1\uninstall.ps1

Warning
This will delete the default Powershell profile, leaving a backup copy on C:\Users\%USERNAME%\Documents\WindowsPowerShell\.

As part the uninstallation, the following will be removed:

  • Minikube Hyper-V VM.

  • %APPDATA%\podman-2.2.1\bin folder.

  • podman-remote-release-windows.zip from Downloads. If you already deleted it it will give you an error but this is expected.

Note
The folder %APPDATA%\podman-2.2.1\ will remain after uninstalling, but you can freely delete it. Also, Minikube will not be uninstalled.

2.8 Changing the memory settings of Minikube VM

You can change the memory settings after installation.

For that, first stop Minikube with minikube stop. Then, determine <maximum_memory> and depending on your needs, either:

  • For dynamic memory allocation

Set-VMMemory minikube -DynamicMemoryEnabled $true -MinimumBytes 1800MB -StartupBytes 1800MB -MaximumBytes `<maximum_memory>`MB -Priority 50 -Buffer 20

  • For static memory allocation Set-VMMemory minikube -DynamicMemoryEnabled $false -StartupBytes <maximum_memory>MB

Then start again Minikube with minikube start.

2.9 Further documentation

Podman website and newsfeed: https://podman.io/

⚠️ **GitHub.com Fallback** ⚠️