-
Notifications
You must be signed in to change notification settings - Fork 1
2. Using Podman and Minikube
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.
"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 runsminikube stop
after saving images. -
minikube_load_images
Loads all the images from the.tar
files generated byminikube_save_images
on the VM, then deletes.tar
files loaded successfully. This command accepts-s
flag, which runsminikube start
before loading images.
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.
In order to build an image and run a container bases on that image, follow these steps:
-
Create the Dockerfile with the recipe to build your image. In this example we assume it is a web application that exposes some port.
-
Open a Powershell window where your Dockerfile is located.
-
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>
. -
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. -
Run the container with
podman run --name <container name> <image tag> -d -p <container port>:<VM port>
. -
You can check your container is running with
podman ps
. -
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. -
Finally, to stop, start and delete your container, you just need to:
-
podman stop <container name>
-
podman start <container name>
-
podman rm <container name>
-
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.
|
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".
For more information about pods: https://developers.redhat.com/blog/2019/01/15/podman-managing-containers-pods
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).
-
-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 seeingInput/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.
-
No GUI as in Docker Desktop.
-
podman-compose
only supports the equivalent todocker-compose up
. -
No Docker Swarm. Use Kubernetes.
-
You can manage pods with Podman, not just containers.
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.
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
.
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.
|
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
.
Minikube docs: https://minikube.sigs.k8s.io/docs/start/
Podman docs https://docs.podman.io/en/latest/
Podman website and newsfeed: https://podman.io/
Podman GitHub: https://github.com/containers/podman
Podman-compose GitHub: https://github.com/containers/podman-compose