Skip to content

aserper/portainer2k8s

Repository files navigation

Portainer to Kubernetes Converter

Portainer to K8s Logo

Tests GHCR Supported Python versions License: MIT

GitHub stars GitHub forks

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.

Installation

Option 1: Local Installation

  1. Clone the repository:

    git clone https://github.com/aserper/portainer2k8s.git
    cd portainer2k8s
  2. Install dependencies:

    pip install -r requirements.txt

Option 2: Docker Container

Pull and run the pre-built Docker image from GitHub Container Registry:

docker run -it ghcr.io/aserper/portainer2k8s:latest

With persistent configuration:

docker run -it -v ~/.portainer2k8s:/app/config \
  ghcr.io/aserper/portainer2k8s:latest

This mounts a local directory to persist your config.yaml between runs.

Building locally:

docker build -t portainer2k8s .
docker run -it portainer2k8s

Usage

Interactive Mode (TUI)

Run the interactive tool to connect to Portainer, browse endpoints, and select containers to export.

python3 portainer_tui.py

The first run will prompt you for your Portainer URL and credentials.

CLI Mode

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"

Configuration

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"

Development

Running Tests Locally

# 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

Code Quality

# Lint with flake8
flake8 .

# Format check with black
black --check .

# Type check with mypy
mypy *.py

License

MIT License

About

A nifty tool to quickly export running portainer/docker configurations to k8s manifests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors