olitheolix / kubernetes_asyncio

Python asynchronous client library for Kubernetes http://kubernetes.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kubernetes Python Client

Build Status PyPI version codecov pypi supported versions

Asynchronous (AsyncIO) client library for the Kubernetes API.

This library is created in the same way as official https://github.com/kubernetes-client/python but uses asynchronous version of swagger-codegen.

My motivation: kubernetes-client/python#324

Installation

From PyPi directly:

pip install kubernetes_asyncio

Development

Install the development packages:

pip install -r requirements.txt
pip install -r test-requirements.txt

You can run the style checks and tests with

flake8 && isort -c
nosetests

Example

To list all pods:

import asyncio
from kubernetes_asyncio import client, config


async def main():
    # Configs can be set in Configuration class directly or using helper
    # utility. If no argument provided, the config will be loaded from
    # default location.
    config.load_kube_config()

    v1 = client.CoreV1Api()
    print("Listing pods with their IPs:")
    ret = await v1.list_pod_for_all_namespaces()

    for i in ret.items:
        print("%s\t%s\t%s" %
              (i.status.pod_ip, i.metadata.namespace, i.metadata.name))


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    loop.close()

More complicated examples, like asynchronous multiple watch or tail logs from pods, you can find in examples/ folder.

About

Python asynchronous client library for Kubernetes http://kubernetes.io/

License:Apache License 2.0


Languages

Language:Python 99.8%Language:Shell 0.2%