podlet
repository·main·Indexed 23 days ago
https://github.com/containers/podletA utility to generate Podman Quadlet files from Podman commands, compose files, or existing Podman objects. It bridges the gap between imperative commands and declarative systemd-managed Quadlet files, supporting the creation of .container, .pod, .kube, .network, .volume, .build, .image, and .artifact files.
What's inside podlet
- Podlet is a tool that generates Podman Quadlet files from Podman commands, compose files, or existing Podman objects. It helps automate the creation of systemd unit files for managing containerized workloads via Podman.
Limitations of Compose conversion
mainWhen converting Compose files using
podlet compose, the following elements are currently not supported:include: Theincludedirective in Compose files is not supported.configs: Composeconfigsare not supported.- External Secrets: Only external
secretsare supported; internal/inline secrets are not. - Extensions: Compose extensions (keys starting with
x-) are not supported. - External Networks/Volumes: External
networksandvolumesare not supported.
Podlet Features and Supported Inputs
mainPodlet supports generating Quadlets from a wide variety of inputs:
Podman Commands
It can convert the following commands into Quadlet files:
podman runpodman pod createpodman kube playpodman network createpodman volume createpodman buildpodman image pullpodman artifact pull
Compose Files
Convert (Docker) compose files into:
- Multiple Quadlet
.containerfiles. - A Quadlet
.podfile paired with.containerfiles. - A Quadlet
.kubefile and Kubernetes Pod YAML. - A
.quadletsfile for use withpodman quadlet install.
Existing Podman Objects
Generate Quadlets from currently existing:
- Containers
- Pods
- Networks
- Volumes
- Images
Important cautions when using Podlet
mainWhen using Podlet to generate Quadlet files (Podman systemd units), keep the following limitations in mind:
- Review generated files: Podlet is a tool to help you get started with Quadlet files, but it is not a complete solution for maintaining them. Always review the generated files before starting the systemd unit.
- No full command validation: Podlet is not a validator for Podman commands. While it parses and validates some options to facilitate Quadlet creation, it does not check for all Podman option incompatibilities or specific formatting requirements.
Generate Quadlet files from Compose files
mainPodlet can convert Docker/Podman Compose files into Quadlet files using the
podlet composecommand. If no file is specified, it searches for standard names likecompose.yaml,compose.yml,docker-compose.yaml, etc., in the current directory.Two modes are available:
- Standard conversion: Creates individual
.containerfiles for each service. --podmode: Creates a.podQuadlet file and links each.containerfile to it using thePod=option.--kubemode: Generates a single Kubernetes YAML file that groups all compose services into a pod.
- Standard conversion: Creates individual
Install Podlet
mainYou can install Podlet using several methods depending on your environment:
- Prebuilt Binary: Download from the GitHub releases page.
- Container: Run it directly using Podman:
podman run ghcr.io/containers/podlet. - Cargo Binstall: Use
cargo binstall podletto get a prebuilt binary. - Cargo: Build and install from source with
cargo install podlet. - Homebrew: Install via macOS/Linux package manager:
brew install podlet.
Run Podlet in a container
mainTo run Podlet inside a container while maintaining access to your local files and Quadlet directories, use the following command. This example mounts the current directory and the user's Podman systemd directory:
podman run --rm --userns keep-id -e HOME -e XDG_CONFIG_HOME --user $(id -u) -v "$PWD":"$PWD" -v "$HOME/.config/containers/systemd/":"$HOME/.config/containers/systemd/" -w "$PWD" --security-opt label=disable --pull=newer ghcr.io/containers/podletNote:
--security-opt label=disablemay be required on SELinux systems.Generate Quadlet files from existing Podman objects
mainIf you have already created containers, pods, networks, volumes, or images in Podman, you can usepodlet generateto create Quadlet files based on those existing live objects. This requirespodmanto be available in yourPATH.Generate Quadlet files from Podman commands
mainYou can generate Podman Quadlet files by prefixing any
podmancommand withpodlet podman. This is particularly useful for converting complexpodman runcommands into.containerfiles, or other object types like.pod,.kube,.network,.volume,.build,.image, or.artifactfiles.To write the output directly to a file instead of printing to stdout, use the
-f, --file <FILE>option. To write directly to the Podman unit directory, use-u, --unit-directory.# Basic usage: converts a run command to a Quadlet file in stdout $ podlet podman run quay.io/podman/hello # Advanced usage: writes a Caddy configuration to a file with an [Install] section and description $ podlet --file . --install --description Caddy \ podman run \ --restart always \ -p 8000:80 \ -p 8443:443 \ -v ./Caddyfile:/etc/caddy/Caddyfile:Z \ -v caddy_data:/data \ docker.io/library/caddy:latestHow Compose services are mapped to Podlet components
mainPodlet converts a
compose_spec::Service(from a Docker Compose file) into a structuredServiceobject. This object splits the service configuration into four distinct categories based on how they are used in the resulting container setup:quadlet: Configuration used to constructQuadletOptions. This includes container lifecycle and networking settings likeports,volumes,env_file,dns,healthcheck, andlabels.podman_args: Configuration used to constructPodmanArgs. These are low-level resource and runtime settings such ascpus,mem_reservation,privileged,tty,ipc, andcgroupsettings.container: Top-level container attributes includingimage,command, andsecurity_opt.unsupported: Fields present in the Compose specification that Podlet cannot currently translate into Quadlets or Podman arguments (e.g.,build,deploy,extends,profiles,scale).
If you are using the library to perform conversions, you should check the
unsupportedfield to ensure no critical configuration is being dropped.Convert Compose files to Kubernetes Pod and PVC YAML
mainThe
Filestruct is used to represent a Kubernetes YAML file generated by converting a Docker Compose specification. It encapsulates a KubernetesPodand any necessaryPersistentVolumeClaims (PVCs) required by the volumes defined in the Compose file.Conversion Logic
When converting from a
Composeobject to aFile:- Supported: Services and Volumes (if they require PVCs).
- Unsupported: The following Compose features will trigger an error during conversion:
includenetworksconfigssecretsextensions
- Requirement: The
namefield in the Compose file must be present.
Serialization
You can generate the final YAML string by calling
serialize_to_yaml(). If PVCs are present, the output will be a multi-document YAML file where the PVCs are listed first, followed by thePoddefinition, separated by---delimiters.How Docker Compose services are converted to Kubernetes Pods
mainPodlet converts a Docker Compose
serviceinto a KubernetesPod. The conversion process maps specific Compose service fields to KubernetesContainerandPodspecifications:- Container Fields:
image,command(args),entrypoint,environment,ports,working_dir,stdin,tty,volume_mounts,resources(limits/requests),security_context(capabilities, privileged, user, SELinux), andlifecycle(viastop_signal). - Pod Fields:
pids_limitandcpusetare added as Pod annotations (io.podman.annotations.pids-limit/{name}andio.podman.annotations.cpuset/{name}). - Healthchecks: Compose
healthcheckcommands are converted into Kubernetesliveness_probeusingexecactions.
Note on Entrypoints: If a Compose
entrypointis a string, Podlet automatically wraps it in/bin/sh -cto ensure execution compatibility in Kubernetes.- Container Fields: