Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k3sprovision-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3sprovision-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file k3sprovision-0.1.0.tar.gz.

File metadata

  • Download URL: k3sprovision-0.1.0.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

Hashes for k3sprovision-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5c91dc2a9e36bd5197cbd105e8fc4f32c2bddb1a2d07c7f602e8151f02949118
MD5 811690f2c3bfd0d2497dd83752ecabc4
BLAKE2b-256 dbf61577463627269d4621e37eece262cd96d59a6dc4b8cf2df4d902e7ed0998

See more details on using hashes here.

File details

Details for the file k3sprovision-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: k3sprovision-0.1.0-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

Hashes for k3sprovision-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7496ecb08a40fcc32bd9cd8ce79266faa936d45d2197b2acfb2de51b55a8774
MD5 c6684459ace622944e6a22e71816d7b8
BLAKE2b-256 6c2def18ffeecf0e777cea875c72348d588d570fe48b22d8dc41d50e7da76e28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page