A package for provisioning k3s clusters.
Project description
k3sprovision
k3sprovision is a Python package for automated provisioning and management of k3s clusters using Ansible and shell commands. It supports master/worker node setup, high availability with Kube-VIP, and integrates with Ansible inventory files.
Features
- Provision k3s clusters with master and worker nodes
- Bootstrap master nodes and join additional masters/workers
- Install and configure Kube-VIP for high availability
- Retrieve and apply Kube-VIP manifests
- Gather host information from Ansible inventory
- Colorized logging and shell command execution
Requirements
- Python 3.8+
- Ansible (Python package)
- PyYAML
- jq, curl, k3sup, kubectl, ssh (available in shell)
Installation
Install via pip (after publishing to PyPI):
pip install k3sprovision
Usage Example
from k3sprovision import ClusterProvisioner
# Example config dictionary
config = {
"cluster": "mycluster",
"inventory": "inventory/inventory.yml",
"k3s_version": "v1.28.5+k3s1",
"kube_vip_version": "v0.6.4",
"kubectl_config": "~/.kube/config",
"ssh_key": "~/.ssh/id_rsa"
}
provisioner = ClusterProvisioner(config)
provisioner.run() # Provisions the cluster end-to-end
API Reference
ClusterProvisioner
Handles provisioning and setup of k3s clusters.
__init__(self, config: dict = None)
Initializes with a config dict or environment variables.
bootstrap_master(self)
Bootstraps the first master node using k3sup.
get_kube_vip_latest_version(self) -> str
Fetches the latest Kube-VIP version from GitHub.
download_kube_vip_file(self)
Downloads the Kube-VIP manifest YAML for the specified version.
install_kube_vip(self)
Installs Kube-VIP for high availability networking.
bootstrap_masters_join_cluster(self)
Joins additional master nodes to the cluster.
bootstrap_worker_join_cluster(self)
Joins worker nodes to the cluster.
run(self)
Runs the full provisioning workflow: master bootstrap, Kube-VIP install, join masters/workers, install cloud provider.
Cluster
Represents a k3s cluster and gathers host info from Ansible inventory.
__init__(self, inventory_file: str, cluster: str)
Loads inventory and variables for the specified cluster group.
hosts
Dictionary with keys master, masters, and workers, each containing host info.
Helper
Utility functions for logging, shell command execution, and YAML parsing.
run_shell(cmd: str, output_return: bool = False, output_print: bool = False) -> str
Runs a shell command and returns or prints output.
get_yaml(filename: str)
Loads a YAML file and returns its contents.
Logging functions
log_info, log_error, log_warning, log_debug, log_critical, log_shell for colorized output.
Directory Structure
k3sprovision/
__init__.py
cluster.py
helper.py
provisioner.py
License
See LICENSE file for details.
Author
Omniopenverse omniopenverse@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file k3sprovision-0.1.1.tar.gz.
File metadata
- Download URL: k3sprovision-0.1.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54a9168830dc125eeab0753252c3ef45bb0f56c384dff18cd5a8bf4b33434ff9
|
|
| MD5 |
44caa68aa41f4d9a2f77c6113af61e00
|
|
| BLAKE2b-256 |
406bbfe6bc1361cde6f0d6dc685bc0093b912a6fe70d5c4a987e37a7a47d725b
|
File details
Details for the file k3sprovision-0.1.1-py3-none-any.whl.
File metadata
- Download URL: k3sprovision-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b8d7a064a5751da85b913d55702d8635c2c7d5d0ae3e71498310a22478560cf
|
|
| MD5 |
f09e3aac668992c876a77ad0608e821a
|
|
| BLAKE2b-256 |
61a35b338da48996b1639a004fa70fe191f1f1b9ec6d1b890b27ab2356bb7c3d
|