Skip to main content

Swarmchestrate k3s client

Project description

k3s-client

A lightweight Python client for managing microservices on Kubernetes k3s clusters. Provides a clean API layer for deploying applications, managing secrets and ConfigMaps, generating Kubernetes manifests from TOSCA definitions, and performing node-aware scheduling operations.


Features

  • Registry Secret Management — Create and rotate Docker registry secrets for private image pulls
  • ConfigMap Management — Create ConfigMaps from literals or files
  • Microservice Lifecycle — Scale, update images, migrate nodes, and delete microservices
  • Manifest Generation — Generate Kubernetes manifests from TOSCA definitions
  • Node-Aware Scheduling — Migrate microservices across nodes using label-based selectors
  • Pod Management — List and launch pods with node affinity support
  • Kubectl Wrapper — Declarative apply and delete via kubectl

Prerequisites

  • Python 3.12 or higher
  • A running k3s server with a valid kubeconfig (default: /etc/rancher/k3s/k3s.yaml)
  • kubectl installed

Installation

git clone https://github.com/Swarmchestrate/k3s-client.git
cd k3s-client
make install

This will install all dependencies and the Puccini TOSCA parser required for manifest generation.

Methods

ApplicationManager

Method Parameters Description
create_registry_secret name, registry, username, password, namespace=None, replace=True Create a Docker registry pull secret
create_configmap name, namespace=None, from_literal=None, from_file=None Create a ConfigMap from literals or files
delete_configmap name, namespace=None Delete a ConfigMap by name
create_registry_secret name, registry, username, password, namespace=None, replace=True Create a Docker registry pull secret
apply_manifest manifest_file, namespace=None Apply a Kubernetes manifest via kubectl
delete_manifest manifest_file Delete resources defined in a manifest
create_microservice deployment_name, image, container_name='app', replicas=1, namespace=None, labels=None, env=None, ports=None, node_selector=None, service_type='ClusterIP' Create a new deployment and optional service
scale_microservice deployment_name, replicas, namespace=None Scale a deployment
update_microservice_image deployment_name, container_name, new_image, namespace=None Update a container image in-place
migrate_microservice_node deployment_name, node_selector, namespace=None Migrate a deployment to a different node
delete_microservice app_label, namespace=None Delete all resources for a given app label
get_pod_node_mapping namespace=None, label_selector=None Return a mapping of pod names to node names

PodManager

Method Parameters Description
list_pods namespace=None, label_selector=None List pods, optionally filtered by label
launch_pod name, image, pod_labels=None, node_labels=None, node_name=None, namespace=None, container_port=None Launch a pod for internal testing with optional node affinity

get_kubernetes_manifest

Function Parameters Description
get_kubernetes_manifest tosca_yaml, image_pull_secret=None Generate Kubernetes manifests from a TOSCA definition

Kubectl

Method Parameters Description
apply manifest_path=None, configmap_name=None, namespace=None, from_literal=None, from_file=None Apply resources declaratively
delete manifest_path Delete resources from a manifest

Examples

The examples/ directory contains complete runnable scripts:

File Description
registry_secret_example.py Managing Docker registry secrets
configmap_example.py Creating ConfigMaps from literals and files
manifest_generator_example.py Generating Kubernetes manifests from TOSCA definitions
manifest_apply_example.py Applying a generated manifest to the cluster
manifest_delete_example.py Deleting resources defined in a manifest
deploy_microservice_example.py Create a new deployment and optional service
scale_microservice_example.py Scale a deployment by replica count
update_microservice_image_example.py Update a deployment container image
migrate_microservice_node_example.py Migrate a deployment to specific nodes
delete_microservice_example.py Delete a microservice deployment and service
pod_node_mapping_example.py Show pod-to-node mapping for a namespace

Run any example:

python examples/scale_microservice_example.py

By default, examples use the k3s kubeconfig at /etc/rancher/k3s/k3s.yaml. You can also override this path in the script or via environment configuration when needed.

Set the environment variable like this:

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Make your changes and add tests where applicable
  4. Run the test suite (pytest)
  5. Open a pull request

License

Licensed under the Apache License 2.0.


Contact

For questions or feedback, reach out to G.Kotak@westminster.ac.uk

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

k3s_client-0.1.3.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

k3s_client-0.1.3-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file k3s_client-0.1.3.tar.gz.

File metadata

  • Download URL: k3s_client-0.1.3.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for k3s_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0fbdd8f906830edef9fd3d326cc2e0ad222f20b7ae40ad7e0422f4199e1f141d
MD5 6989cde2d4fe7d9ffa40c72cd14b1294
BLAKE2b-256 a02a06680df5b5b78e25d50327b26f894a872562f4a88956c4f2ea78edc9948f

See more details on using hashes here.

Provenance

The following attestation bundles were made for k3s_client-0.1.3.tar.gz:

Publisher: release.yml on Swarmchestrate/k3s-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file k3s_client-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: k3s_client-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for k3s_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2bd90ce46c4510b7008d45b3c74b8f525762c6bb6d9bc30425bdd7d2088c1c1b
MD5 216430547e7f39b020524213b0739c27
BLAKE2b-256 e6ee5cad1d58f14fb8b4d1cba4cd6b90f5c3a99c0801a6b524d9de0cd88c705b

See more details on using hashes here.

Provenance

The following attestation bundles were made for k3s_client-0.1.3-py3-none-any.whl:

Publisher: release.yml on Swarmchestrate/k3s-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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