Skip to main content

k3s-client

A lightweight Python library for managing microservices on Kubernetes k3s clusters. It provides direct helpers for manifest orchestration, registry/configmap operations, pod operations, and TOSCA-based manifest generation.

Python Library Package

This project is published as k3s-client and imported as k3s_client.

  • Main classes:
    • k3s_client.api.applications.ApplicationManager
    • k3s_client.api.pods.PodManager

Quick start (PyPI):

pip install k3s-client

Basic usage:

from k3s_client.api.applications import ApplicationManager

manager = ApplicationManager(dry_run_by_default=True)

# Preview a runtime change without executing it
preview = manager.scale_to(msid="productpage", count=3)

# Execute for real
result = manager.scale_to(msid="productpage", count=3, dry_run=False)

Features

  • Registry Secret Management — Create and rotate Docker registry secrets for private image pulls
  • Microservice Scaling — Scale deployments and manipulate pods for optimizer workflows
  • Manifest Generation — Generate Kubernetes manifests from TOSCA definitions
  • Pod Mapping — Query pod-to-node mapping for placement decisions

Prerequisites

  • Python 3.12 or higher
  • Kubernetes Python SDK (kubernetes package)

Methods

All microservices are managed in the default namespace; there is no namespace parameter.

Class guide:

  • Use ApplicationManager as the main entry point.

ApplicationManager

Method Parameters Description
create_registry_secret name, registry, username, password, email=None, replace=True, dry_run=None Create a Docker registry pull secret
apply_manifest manifest_file, dry_run=None Apply a Kubernetes manifest
delete_manifest manifest_file, dry_run=None Delete resources defined in a manifest
apply_tosca tosca_file=None, tosca_content=None, image_pull_secret=None, acme_email=None, dry_run=False, output_manifest_file=None One-call flow: generate manifests from TOSCA and optionally apply with standardized output
create_pod msid, nodeid=None, dry_run=None Create a runtime pod through the runtime client
delete_pod msid, podid=None, dry_run=None Delete a runtime pod through the runtime client
scale_to msid, count, dry_run=None Scale a deployment through the runtime client
migrate_pod msid, podid=None, nodeid=None, dry_run=None Migrate pod placement through the runtime client
get_pod_node_mapping label_selector=None, dry_run=None Return pod-to-node mapping by microservice

Deployment model: apply workloads with apply_manifest, manage runtime scaling/placement with the runtime methods, and clean up with delete_manifest.

Runtime model: runtime operations update live cluster state and do not rewrite source YAML on disk. For Deployment-managed workloads, create_pod(msid) and delete_pod(msid) map to +1 / -1 scaling, scale_to(msid, count) sets exact replicas, and migrate_pod(msid, podid, nodeid) uses delete/recreate placement.

Field managers are intentionally separated: tosca-controller for generated manifest apply and swarm-optimiser for runtime pinned deployment apply. This avoids runtime placement changes being overwritten by later manifest re-apply operations.

Dry Run (All ApplicationManager Methods)

All ApplicationManager methods support dry-run behavior. If dry_run is omitted, the manager uses dry_run_by_default. If dry_run=True, the call executes Kubernetes server-side dry-run (dry_run="All") for write operations and does not persist changes. If dry_run=False, the call executes normally.

Dry-run responses keep compatibility metadata (mode, executed, and params) and include result with the real API dry-run response payload. apply_tosca additionally includes manifest summary fields (manifest.file, resource count, kind summary) and runs the apply step in server-side dry-run so apply_response and result are populated without persisting resources.

Return-shape note: non-dry-run write calls keep human-readable status strings in many paths, while dry-run returns structured API payloads in result (objects/lists, and aggregated details for multi-resource operations).


PodManager

Method Parameters Description
list_pods label_selector=None List pods, optionally filtered by label

get_kubernetes_manifest

Function Parameters Description
get_kubernetes_manifest tosca_file=None, tosca_content=None, image_pull_secret=None, acme_email=None Generate Kubernetes manifests from a TOSCA definition

Provide exactly one input source: tosca_file or tosca_content. .


Examples

Use these scripts from the examples/ folder for end-to-end usage:

Most examples assume in-cluster execution by default so they can run unchanged inside the Swarm Agent pod. For local development, pass kubeconfig_path explicitly.

Example script Description
manifest_generator_example.py Generate Kubernetes manifests from a TOSCA input
manifest_apply_example.py Apply an existing manifest file
manifest_delete_example.py Delete resources from a manifest file
apply_tosca_example.py Generate and apply from TOSCA in one flow
scale_microservice_example.py Scale a microservice deployment
pod_runtime_operations_example.py Create, delete, and migrate runtime pods
registry_secret_example.py Create/update registry pull secrets

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

Metadata

Release files for k3s-client 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3s-client 0.3.3
File Size Uploaded Provenance Actions
k3s_client-0.3.3.tar.gz 37.7 kB With provenance Details for k3s_client-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for k3s-client 0.3.3
File Interpreter ABI Platform Actions
k3s_client-0.3.3-py3-none-any.whl Python 3 none any Details for k3s_client-0.3.3-py3-none-any.whl

Total release size: 70.4 kB

Release files / k3s_client-0.3.3.tar.gz

Download URL k3s_client-0.3.3.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fcbf6cdfe50a4cd3797dd3418730e0e5d1aa17e4bfea6e3ba8ef4b8f49230144
BLAKE2b-256 checksum
How to use checksums
65da5f0a48a854c9e44bdf8e8e045a5adfd661f2a6eb9c8307618f8d63f71fce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / k3s_client-0.3.3-py3-none-any.whl

Download URL k3s_client-0.3.3-py3-none-any.whl
Size 32.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48edec9a033528ec7bf5db350380383188c31a5141ac18aead9b2b3b080c1175
BLAKE2b-256 checksum
How to use checksums
2634d460d7b051a1aeb4fd54029b20fd8ac488397338379510f52099c3295ce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Security for k3s-client 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for k3s_client-0.3.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page