Skip to main content

This library contains:

  • Objects for
    • Creating, updating and deleting a Kubernetes cluster.

    • Deploying various objects on Kubernetes cluster.

    • Running Jmeter Load tests on Kubernetes cluster.

Table of Contents

Installation

python-autoqube_kubernetes is compatible with Python 3.x. It is listed on PyPi as ‘autoqube_kubernetes’. The recommended way to install is via pip:

pip install autoqube_kubernetes

Prerequisites

  • kops: kops is a command line utility tool required to manage kubernetes cluster. The installation information is available at kops installation.

  • kubectl: kubectl is a command line utility tool required to manage various objects on existing kubernetes cluster. The installation information is available at kubectl installation.

  • dns-zone: A public hosted zone should be created for AWS which would be the same as the name of the cluster. Please refer creating dns-zone.

KubernetesHandler

KubernetesHandler object will create, delete cluster and run load tests.

Kubernetes cluster

Currently the cluster creation is supported only on AWS cloud platform.

For creating a new Kubernetes cluster, the following parameters are needed:

  • cloud_provider : The cloud provider on which the cluster needs to be created.

  • cluster_config : The configuration details for the cluster.

  • env_config : The environment configuration for storage of cloud provider essential keys.

A typical cluster configuration file would be like

config = {
    "cloud_provider": "AWS",
    "cluster_config": {
        'node-count':  2,
        'master-size': 't2.small',
        'master-zones': 'us-west-2a',
        'zones':  'us-west-2a',
        'name': 'aq.autoqube.io',
        'node-size': 't2.small',
        'ssh-public-key': '/Users/autoqube/.ssh/id_rsa.pub',
        'dns-zone': 'aq.autoqube.io',
    },
    "env_config": {
        'AWS_ACCESS_KEY_ID': '*********************',
        'AWS_SECRET_ACCESS_KEY': '***********************',
        'AWS_REGION': 'us-west-2',
        'KUBECONFIG': '/Users/autoqube/kubernetes/aq.autoqube.io/kubeconfig',
        'KOPS_STATE_STORE': 's3://agent-kops-store'
    },
}

For better understanding or debugging of various processes running behind, setup a logging functionality.

from autoqube_kubernetes import KubernetesHandler
import config
import logging

root_logger = logging.getLogger()
console_handler = logging.StreamHandler()

root_logger.setLevel(logging.INFO)
root_logger.addHandler(console_handler)

kubernetes_handler = KubernetesHandler(config)
kubernetes_handler.create_cluster() # Creation of cluster with the above configuration.
# kubeconfig will be stored in the path specified in the configuration.
kubernetes_handler.delete_cluster() # Deletion of cluster with the above configuration.

Load Testing

  • Currently only ‘jmeter’ load testing is supported on kubernetes cluster.

  • Load testing using jmeter on a kubernetes cluster has been inspired from the following blog.

  • The results of the load test can be visually seen on grafana service dashboards.

  • The templates for deployment of various kubernetes objects required for jmeter load testing can be downloaded from Jmeter Load Test Templates.

  • Extract the downloaded templates and place them in location accessible by python.

  • The following parameters are needed for load testing
    • load_config - The configuration details about type of load test and the templates for kubernetes objects.

    • test_file_config - The configuration details about the test files for load test.

A sample configuration would be like

load_config = {
     'test_type': 'jmeter',
     'templates_path': '/Users/autoqube/kubernetes/load_testing/k8s_templates/jmeter/'
 }
 test_file_config = {
     'test_files': ['./tmp/sample.jmx', './tmp/sample.csv']
 }

KubernetesHandler will create the necessary objects on cluster and run load tests.

 # After creation of kubernetes cluster using 'kubernetes_handler'.
 kubernetes_handler.create_load_test(load_config)
 # Creates pods, deployments, services and other objects required for
 # load testing on cluster.

 kubernetes_handler.run_load_test(test_file_config)
 # Run load tests using the test files provided in the configuration

 kubernetes_handler.destroy_load_test(load_config)
# Once the tests are complete, all the resources created can be destroyed
# and only empty cluster will remain.

KubernetesClient

KubernetesClient can be used to perform various actions on existing cluster like:
  • Creating objects from yaml files

  • Destroying resources on cluster

  • Listing all the pods and services on cluster

  • Executing commands on a specific pod

  • Copy files to a specific pod

kubeconfig of a cluster is required.

from autoqube_kubernetes import KubernetesClient

kubernetes_client = KubernetesClient('/path/to/kubeconfig')
namespace = 'autoqube' # Namespace on which the operations are to be performed.
kubernetes_client.create_object('/path/to/yaml', namespace) # Creates object from yaml file.
kubernetes_client.get_pod_list(namespace) # Lists all the pods.
kubernetes_client.get_service_list(namespace) # Lists all the services.
podname = 'autoqube-jmeter'
commands_list = ['cd ~', 'ls']
kubernetes_client.execute_commands(podname, commands_list, namespace) # Executes the commands on a specific pod.
kubernetes_client.destroy_all_resources(namespace) # Destroys all resources in a given namespace.

Metadata

Release files for autoqube-kubernetes 1.0.2

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

Source distribution (sdist)

Source distribution for autoqube-kubernetes 1.0.2
File Size Uploaded Provenance
autoqube_kubernetes-1.0.2.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for autoqube-kubernetes 1.0.2
File Interpreter ABI Platform
autoqube_kubernetes-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.9 kB

Release files / autoqube_kubernetes-1.0.2.tar.gz

Download URL autoqube_kubernetes-1.0.2.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cccd9367987169790065115b6bfde19dcca1f47ccb3ed6c848c1a427553f039d
BLAKE2b-256 checksum
How to use checksums
1a01867d775782aae79fa06092ba28c7d01e6111a36febe9391fff5ffc9b365c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.2

Release files / autoqube_kubernetes-1.0.2-py3-none-any.whl

Download URL autoqube_kubernetes-1.0.2-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe39f17f0e465596b1dc56ae26152446fd7769c20d745405b853b78d92743d66
BLAKE2b-256 checksum
How to use checksums
5ea6fe90a312d64ce13c02626c840f4f6aa24fbc3e00759f7a6b468b87e50319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.2

Security for autoqube-kubernetes 1.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

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