A simplified tool for deploying applications to Kubernetes and OpenShift clusters. This tool supports both Kubernetes and OpenShift clusters and can authenticate using either kubeconfig files or service account tokens.
- Multi-cluster support: Works with both Kubernetes and OpenShift
- Flexible authentication: Supports kubeconfig files or service account tokens
- Ansible-based: Uses Ansible playbooks for deployment, making it easy to extend
- Simple CLI: Easy-to-use command-line interface
- Role-based: Applications are defined as Ansible roles
The easiest way to get started is using the setup script:
# Run the setup script (creates venv, installs dependencies, optionally sets up kind cluster)
./setup.shOr manually:
# 1. Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# 2. Install the package
pip install -e .Use the provided setup script for a complete setup:
./setup.shThis script will:
- Check prerequisites (Python 3.8+, pip, kubectl, kind)
- Create a virtual environment
- Install all dependencies
- Optionally create a kind cluster for testing
- Verify the installation
# Clone the repository
git clone <repository-url>
cd k8s-apps-deployer
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# Install the package
pip install -e .The package will be installed in editable mode, so you can make changes to the source code without reinstalling.
The tool supports two authentication methods:
-
Kubeconfig (default): Uses your default kubeconfig file (
~/.kube/config)k8sdeploy deploy mysql -n mysql
-
Service Account Token: Use environment variables or CLI flags
export K8S_TOKEN="your-token" export K8S_SERVER="https://api.example.com:6443" k8sdeploy deploy mysql -n mysql
Or use CLI flags:
k8sdeploy --token "your-token" --server "https://api.example.com:6443" deploy mysql -n mysql
-
Kubeconfig Context (optional): Select a specific context from kubeconfig
k8sdeploy --context my-context deploy mysql -n mysql
If
--contextis not provided, the kubeconfigcurrent-contextis used.
Global options must be passed before the command, for example:
k8sdeploy --kubeconfig ~/.kube/config --context my-context deploy mysql -n mysqlk8sdeploy listk8sdeploy deploy <application> -n <namespace>Options:
-n, --namespace: Namespace to deploy to-f, --force-cleanup: Cleanup application before deploying-e, --extra-vars: Extra variables as JSON string--kubeconfig: Path to kubeconfig file--context: Kubeconfig context to use (optional)--token: Service account token--server: API server URL (required with --token)--insecure-skip-tls-verify: Skip TLS certificate verification-v, --verbose: Enable verbose logging
Example:
k8sdeploy deploy mysql -n mysql
k8sdeploy deploy mysql -n mysql -e '{"storage_size": "5Gi"}'
k8sdeploy --context my-context deploy mysql -n mysqlk8sdeploy remove <application> -n <namespace>k8sdeploy validate <application> -n <namespace>The following applications are available:
- mysql: MySQL database with persistent storage
- mongodb: MongoDB database with persistent storage
- redis: Redis cache with persistent storage
- basic-pod: Simple nginx pod
- pvc: Persistent volume claim
The project is structured as follows:
k8s-apps-deployer/
├── src/
│ └── k8sdeployer/
│ ├── __init__.py
│ ├── cli.py # CLI interface
│ ├── cluster.py # Cluster connection management
│ ├── application_factory.py # Application factory
│ ├── apps/
│ │ ├── base.py # Base application class
│ │ └── ansible_app.py # Ansible-based application
│ └── ansible/
│ ├── deploy.yml # Deploy playbook
│ ├── remove.yml # Remove playbook
│ ├── validate.yml # Validate playbook
│ └── roles/ # Application roles
│ ├── mysql/
│ ├── mongodb/
│ ├── redis/
│ ├── basic-pod/
│ └── pvc/
├── pyproject.toml
├── requirements.txt
└── README.md
To add a new application, create a new Ansible role in src/k8sdeployer/ansible/roles/:
-
Create the role directory structure:
roles/your-app/ ├── defaults/ │ └── main.yml ├── tasks/ │ ├── main.yml │ ├── deploy.yml │ ├── cleanup.yml │ └── validate.yml └── templates/ # Optional -
The role should handle three actions:
deploy: Deploy the application (whenwith_deploy: true)cleanup: Remove the application (whenwith_cleanup: true)validate: Validate the application (whenwith_validate: true)
-
Use the
k8sAnsible module for all Kubernetes/OpenShift operations to ensure compatibility with both platforms.
This project is a simplified version with the following improvements:
- Simplified architecture: Removed complex inheritance hierarchies
- K8s/OpenShift compatibility: All roles use
k8sAnsible module instead ofoccommands - Flexible authentication: Supports both kubeconfig and service account tokens
- Cleaner CLI: Simplified command structure
- Better error handling: More informative error messages
Apache-2.0