This tool converts Docker containers managed by Portainer into Kubernetes manifests (Deployment + Service). It supports both an interactive terminal UI (TUI) and a command-line interface (CLI) for automation.
-
Clone the repository:
git clone https://github.com/aserper/portainer2k8s.git cd portainer2k8s -
Install dependencies:
pip install -r requirements.txt
Pull and run the pre-built Docker image from GitHub Container Registry:
docker run -it ghcr.io/aserper/portainer2k8s:latestWith persistent configuration:
docker run -it -v ~/.portainer2k8s:/app/config \
ghcr.io/aserper/portainer2k8s:latestThis mounts a local directory to persist your config.yaml between runs.
Building locally:
docker build -t portainer2k8s .
docker run -it portainer2k8sRun the interactive tool to connect to Portainer, browse endpoints, and select containers to export.
python3 portainer_tui.pyThe first run will prompt you for your Portainer URL and credentials.
Use the CLI for direct conversion or scripting.
python3 portainer_to_k8s.py cli --url <URL> --container <NAME_OR_ID> --api-key <KEY>Example:
python3 portainer_to_k8s.py cli \
--url https://portainer.local \
--container my-app \
--namespace production \
--api-key "your-api-key"Connection settings are stored in config.yaml. This file is created automatically by the TUI or can be created manually.
portainer:
url: "https://portainer.local"
endpoint_id: 1
auth:
method: "api_key"
api_key: "your-api-key"# Install development dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage report
pytest --cov=.
# Run specific test file
pytest tests/test_endpoints.py# Lint with flake8
flake8 .
# Format check with black
black --check .
# Type check with mypy
mypy *.pyMIT License
