Skip to main content

A Python based helper to setup a K3s based clusters using declarative configuration.

Project description

K3sSleipnir - Deploying K3s based Platforms

Named after the workhorse SSCV Sleipnir. The name itself is from Norse mythology.

A Python based helper to setup a K3s based clusters using declarative configuration.

Configuration is done via YAML file(s) that describe your desired end-state of your homelab k3s cluster.

Features:

  • Support for installing a k3s single node cluster on a remote server
  • Support for installing a k3s multi node cluster on a remote servers
  • Sensitive data (secrets) can be pulled from AWS Secrets Manager
  • The YAML format follows a similar format to standard Kubernetes YAML files and should therefore be very familiar
  • Several clusters can be defined in the same configuration file - ideal to test scenarios with multiple running clusters
  • Support for cloning Git repositories to reference additional files/manifests
  • Combine one or more cluster configuration for kubectl into a single file. Can also merge configuration with an existing file.
  • Execute additional commands post cluster provisioning.

[!NOTE] There are some limitations in the declarative approach but these will be discussed in the remainder of the guide.

Future work:

  • Should there be interest, more public cloud providers and services can be supported for secrets management and DNS
  • Potentially support declarative definitions of public cloud based virtual machines on which to install and run k3s

[!IMPORTANT] Keep in mind this is a personal project that I am just happy to share. Therefore, please use issues for support (for now) and keep in mind that the current codebase was hacked together in a couple of days, so it is not optimized, neither pretty... you have been warned :-)

Minimum Requirements

Assuming each server conforms to the official k3s requirements, also take note of the following:

  • Each server must have an SSH server running
  • Each server must have some basic packages installed, including:
    • sudo (with visudo)
    • curl
    • podman or docker to execute scripts post installation (also on the system running the homelab command)

For convenience, it is highly recommended to use SSH keys for password less authentication.

Assuming each server has a user called k3s, add the following to the sudoers file:

k3s ALL = NOPASSWD: /usr/local/bin/k3s-uninstall.sh
k3s ALL = NOPASSWD: /tmp/k3s_install.sh
k3s ALL = NOPASSWD: /tmp/web-forward-into-k3s.sh
k3s ALL = NOPASSWD: /usr/local/bin/k3s-agent-uninstall.sh

Executing commands on the remote servers requires an SSH private key available on the system that will run the utility.

Installing the Provisioning script

Install using PIP

This feature is not yet supported, but it is one of the end-goals

Usage from Cloning this Repository

Clone the repository and change into the project root.

Run the following:

# Use a Python virtual environment
python3 -m venv venv
. venv/bin/activate
pip3 install --upgrade -r requirements.txt

# Run the tool
cd src
python3 -m homelab.homelabctl --help

# Create a convenient alias:
export SRC="${PWD}"
alias homelab="cd ${SRC} && python3 -m homelab.homelabctl "

Quick Start

[!NOTE] The full specification is documented in the SPEC.md file.

At it's most basic, a cluster needs at least one server in order to deploy K3s on a single node.

The most minimal configuration is therefore something like the following which will install K3s as a single node cluster on the defined server:

---
apiVersion: v1
kind: Server
metadata:
  name: my-server
spec:
  address: 10.0.0.1
  credentials:
    credentialsType: private-key
    value: /path/to/private-key
    username: k3s
---
apiVersion: v1
kind: K3sCluster
metadata:
  name: my-cluster
spec:
  tasks:
    - cleanupPreviousClusterDeployment
    - installK3s
  servers:
    - serverName: my-server
  targetKubeConfig: /home/user/homelab_clusters.yaml

Each time the command homelab apply -f /home/user/my-homelab.yaml is run, any existing deployment of K3s on my-server will be removed and a new installation will be done.

As a final step, the configuration file /home/user/homelab_clusters.yaml will created, if it does not yet exist. If the file does exist and contains a previous definition of the deployment, the configuration will be updated. If the file exists with configurations of other clusters, the configuration of the new cluster will be added or updated, depending if it already exists or not.

See the examples/ directory for some additional examples.

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

k3ssleipnir-0.0.1.tar.gz (42.1 kB view details)

Uploaded Source

Built Distribution

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

k3ssleipnir-0.0.1-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file k3ssleipnir-0.0.1.tar.gz.

File metadata

  • Download URL: k3ssleipnir-0.0.1.tar.gz
  • Upload date:
  • Size: 42.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for k3ssleipnir-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a90bd554beb746b6f5208826d2e61f46b6fcc9450659f8a93e90a4c12269fe43
MD5 6e2dc512fc7206135ea4f85bc7f6000d
BLAKE2b-256 0a4c0e455916ca33a560a44c08796209aa1c960c79e73a41a0883f1579b5e206

See more details on using hashes here.

File details

Details for the file k3ssleipnir-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: k3ssleipnir-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for k3ssleipnir-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 549d1a6c83b7cf0d0ad4acdc50653f2b3412968bf09e68883667da1058fb229d
MD5 bf6328c105872a09a9832a084686d2f0
BLAKE2b-256 3487ed1e22bb7c6d002013e1a2d30f726990c952a4c82e40fa3a6c4ad4285d02

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