Rancher Kubernetes API compatible with RKE, RKE2 and maybe others?

Overview

kctl

Rancher Kubernetes API compatible with RKE, RKE2 and maybe others?


Documentation is WIP.


Quickstart

pip install --upgrade kctl

Usage

https://ranchercluster.com/k8s/clusters/c-m-xxxxxx """ KctlClient.v1.list_apps_deployment() """ All v1 methods will now return the specified cluster context { 'type': 'collection', 'links': {'self': 'https://ranchercluster.com/k8s/clusters/c-m-xxxxxx/v1/apps.deployments/fleet-default'}, 'createTypes': {'apps.deployment': 'https://ranchercluster.com/k8s/clusters/c-m-xxxxxx/v1/apps.deployments'}, 'actions': {}, 'resourceType': 'apps.deployment', 'revision': '6671325', 'data': [] } """ ">
from lazycls.envs import set_env_from_dict


"""
---
Primary Configuration that takes env variables first.
---

host = envToStr('KCTL_HOST', 'http://localhost')
api_key = envToStr('KCTL_API_KEY')
api_key_prefix = envToStr('KCTL_API_KEY_PREFIX', 'token:')
api_token = envToStr('KCTL_API_TOKEN')
username = envToStr('KCTL_API_USERNAME')
password = envToStr('KCTL_API_PASSWORD')
auth_prefix = envToStr('KTCL_AUTH_PREFIX', 'authorization')

---
Rancher Specific Configuration
---

host: str = KctlCfg.host,
api_version: str = 'v1',
api_token: str = KctlCfg.api_token,
ssl_verify: bool = True,
strict: bool = False,
cache_time: int = 86400,
cache_dir: Union[Path, str] = DefaultCacheDir,
rancher_default_cluster: str = None,
rancher_fleet_name: str = 'fleet-default',
clusters_enabled: List[str] = [],
clusters_disabled: List[str] = []

---
Then validates against env variables during initialization, prioritizing env variables.
---

api_version = envToStr('KCTL_API_VERSION', api_version or 'v1')
ssl_verify = envToBool('KCTL_SSL_VERIFY', str(ssl_verify))
strict = envToBool('KCTL_STRICT', str(strict))
cache_time = envToInt('KCTL_CACHE_TIME', cache_time)
cache_dir = to_path(envToStr('KCTL_CACHE_DIR', None) or cache_dir)

rancher_default_cluster = envToStr('KCTL_RANCHER_DEFAULT_CLUSTER', rancher_default_cluster)
rancher_fleet_name = envToStr('KCTL_RANCHER_FLEET_NAME', rancher_fleet_name)

# If both are empty, then it will assume all clusters are enabled.
clusters_enabled = envToList('KCTL_CLUSTERS_ENABLED', clusters_enabled)
clusters_disabled = envToList('KCTL_CLUSTERS_DISABLED', clusters_disabled)

"""

data = {
    'KCTL_HOST': 'https://ranchercluster.com',
    'KCTL_API_TOKEN': 'token-xxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyy'
}

set_env_from_dict(data, override=True)
from kctl.client import KctlClient

## Rancher Specific
## This will build the object class dynamically
## enabling v1/v3 api methods.
## v3 is typically the management cluster
## v1 is cluster specific

KctlClient.build_rancher_ctx()

## KctlClient is a Class that doesnt require initialization

## Sync Method
cs = KctlClient.v3.list_cluster()

## Async Method
cs = await KctlClient.v3.async_list_cluster()

cs.data[-1].name

"""
local
"""

## Change Cluster Context

KctlClient.set_cluster('staging-cluster')

KctlClient.v1.url
"""
Now the primary api url will be called using the proper k8s path

-> https://ranchercluster.com/k8s/clusters/c-m-xxxxxx

"""

KctlClient.v1.list_apps_deployment()

"""
All v1 methods will now return the specified cluster context

{
    'type': 'collection', 
    'links': {'self': 'https://ranchercluster.com/k8s/clusters/c-m-xxxxxx/v1/apps.deployments/fleet-default'}, 
    'createTypes': {'apps.deployment': 'https://ranchercluster.com/k8s/clusters/c-m-xxxxxx/v1/apps.deployments'}, 
    'actions': {}, 
    'resourceType': 'apps.deployment', 
    'revision': '6671325', 
    'data': []
}
"""

Enhancements

This library borrows the dynamic initialization method from the primary rancher-client python library with several enhancements.

  • Async and Sync support via httpx / lazyapi, which can be initialized from a sync environment.

  • All async methods are accessed with async_ prefix of the same sync methods.

  • Inclusion of kubernetes python client which can be called via KctlClient.api, allowing setting of credentials once. Although this use case has not been extensively tested. (or rather, at all.)

  • Dynamic Access of downstream clusters without requiring reinitialization of the client

  • Enables context switching between clusters

  • Lazy caching of the api schema in kctl/kctl/.kctlcache

  • Enables access of v1/v3 api methods within the same client.

  • All returned results are objects, allowing dynamic access of object attributes, rather than strictly dict based.

  • Adds support for fleet namespaces to ensure proper url handling


Credits / Libraries Used

  • rancher-client: inspired dynamic schema initialization

  • kubernetes: included to manage credentials

  • lazyapi: personal library that is used to create the httpx clients.

  • lazycls: personal library that contains a lot of utility functions that enables this library to be as slim as possible.

You might also like...
A Kubernetes operator that creates UptimeRobot monitors for your ingresses

This operator automatically creates uptime monitors at UptimeRobot for your Kubernetes Ingress resources. This allows you to easily integrate uptime monitoring of your services into your Kubernetes deployments.

A Simple script to hunt unused Kubernetes resources.

K8SPurger A Simple script to hunt unused Kubernetes resources. Release History Release 0.3 Added Ingress Added Services Account Adding RoleBindding Re

Run Oracle on Kubernetes with El Carro

El Carro is a new project that offers a way to run Oracle databases in Kubernetes as a portable, open source, community driven, no vendor lock-in container orchestration system. El Carro provides a powerful declarative API for comprehensive and consistent configuration and deployment as well as for real-time operations and monitoring.

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions
Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

Chartreuse: Automated Alembic migrations within kubernetes
Chartreuse: Automated Alembic migrations within kubernetes

Chartreuse: Automated Alembic SQL schema migrations within kubernetes "How to automate management of Alembic database schema migration at scale using

Caboto, the Kubernetes semantic analysis tool
Caboto, the Kubernetes semantic analysis tool

Caboto Caboto, the Kubernetes semantic analysis toolkit. It contains a lightweight Python library for semantic analysis of plain Kubernetes manifests

Hubble - Network, Service & Security Observability for Kubernetes using eBPF
Hubble - Network, Service & Security Observability for Kubernetes using eBPF

Network, Service & Security Observability for Kubernetes What is Hubble? Getting Started Features Service Dependency Graph Metrics & Monitoring Flow V

A charmed operator for running PGbouncer on kubernetes.

operator-template Description TODO: Describe your charm in a few paragraphs of Markdown Usage TODO: Provide high-level usage, such as required config

Quick & dirty controller to schedule Kubernetes Jobs later (once)

K8s Jobber Operator Quickly implemented Kubernetes controller to enable scheduling of Jobs at a later time. Usage: To schedule a Job later, Set .spec.

Releases(v0.0.1)
Owner
Chief Architect @ Growth Engine
Simple ssh overlay for easy, remote server management written in Python GTK with paramiko

Simple "ssh" overlay for easy, remote server management written in Python GTK with paramiko

kłapouch 3 May 01, 2022
Hw-ci - Hardware CD/CI and Development Container

Hardware CI & Dev Containter These containers were created for my personal hardware development projects and courses duing my undergraduate degree. Pl

Matthew Dwyer 6 Dec 25, 2022
Helperpod - A CLI tool to run a Kubernetes utility pod with pre-installed tools that can be used for debugging/testing purposes inside a Kubernetes cluster

Helperpod is a CLI tool to run a Kubernetes utility pod with pre-installed tools that can be used for debugging/testing purposes inside a Kubernetes cluster.

Atakan Tatlı 2 Feb 05, 2022
Repository tracking all OpenStack repositories as submodules. Mirror of code maintained at opendev.org.

OpenStack OpenStack is a collection of interoperable components that can be deployed to provide computing, networking and storage resources. Those inf

Mirrors of opendev.org/openstack 4.6k Dec 28, 2022
Remote Desktop Protocol in Twisted Python

RDPY Remote Desktop Protocol in twisted python. RDPY is a pure Python implementation of the Microsoft RDP (Remote Desktop Protocol) protocol (client a

Sylvain Peyrefitte 1.6k Dec 30, 2022
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:

Latest Salt Documentation Open an issue (bug report, feature request, etc.) Salt is the world’s fastest, most intelligent and scalable automation engi

SaltStack 12.9k Jan 04, 2023
A lobby boy will create a VPS server when you need one, and destroy it after using it.

Lobbyboy What is a lobby boy? A lobby boy is completely invisible, yet always in sight. A lobby boy remembers what people hate. A lobby boy anticipate

226 Dec 29, 2022
Find-Xss - Termux Kurulum Dosyası Eklendi Eğer Hata Alıyorsanız Lütfen Resmini Çekip İnstagramdan Bildiriniz

FindXss Waf Bypass Eklendi !!! PRODUCER: Saep UPDATER: Aser-Vant Download: git c

Aser 2 Apr 17, 2022
MLops tools review for execution on multiple cluster types: slurm, kubernetes, dask...

MLops tools review focused on execution using multiple cluster types: slurm, kubernetes, dask...

4 Nov 30, 2022
A Kubernetes operator that creates UptimeRobot monitors for your ingresses

This operator automatically creates uptime monitors at UptimeRobot for your Kubernetes Ingress resources. This allows you to easily integrate uptime monitoring of your services into your Kubernetes d

Max 49 Dec 14, 2022
Ajenti Core and stock plugins

Ajenti is a Linux & BSD modular server admin panel. Ajenti 2 provides a new interface and a better architecture, developed with Python3 and AngularJS.

Ajenti Project 7k Jan 03, 2023
This is a tool to develop, build and test PHP extensions in Docker containers.

Develop, Build and Test PHP Extensions This is a tool to develop, build and test PHP extensions in Docker containers. Installation Clone this reposito

Suora GmbH 10 Oct 22, 2022
Organizing ssh servers in one shell.

NeZha (哪吒) NeZha is a famous chinese deity who can have three heads and six arms if he wants. And my NeZha tool is hoping to bring developer such mult

Zilin Zhu 8 Dec 20, 2021
Docker Container wallstreetbets-sentiment-analysis

Docker Container wallstreetbets-sentiment-analysis A docker container using restful endpoints exposed on port 5000 "/analyze" to gather sentiment anal

145 Nov 22, 2022
Big data on k8s

# microsoft azure # https://docs.microsoft.com/en-us/cli/azure/install-azure-cli az account set --subscription [] az aks get-credentials --resource-g

Luan Moreno 22 Dec 24, 2022
NixOps is a tool for deploying to NixOS machines in a network or cloud.

NixOps NixOps is a tool for deploying to NixOS machines in a network or the cloud. Key features include: Declarative: NixOps determines and carries ou

Nix/Nixpkgs/NixOS 1.2k Jan 02, 2023
Supervisor process control system for UNIX

Supervisor Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems. Supported Platf

Supervisor 7.6k Dec 31, 2022
Ingress patch example by Kustomize

Ingress patch example by Kustomize

Jinu 10 Nov 14, 2022
Honcho: a python clone of Foreman. For managing Procfile-based applications.

___ ___ ___ ___ ___ ___ /\__\ /\ \ /\__\ /\ \ /\__\ /\

Nick Stenning 1.5k Jan 03, 2023
This project shows how to serve an TF based image classification model as a web service with TFServing, Docker, and Kubernetes(GKE).

Deploying ML models with CPU based TFServing, Docker, and Kubernetes By: Chansung Park and Sayak Paul This project shows how to serve a TensorFlow ima

Chansung Park 104 Dec 28, 2022