tomplus/kubernetes_asyncio
소개
Kubernetes용 Python 비동기 클라이언트 라이브러리입니다. http://kubernetes.io/
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalKubernetes Python Client
Asynchronous (AsyncIO) client library for the Kubernetes API.
This library is created in the same way as the official https://github.com/kubernetes-client/python but uses asynchronous version of OpenAPI generator. My motivation is described here: https://github.com/kubernetes-client/python/pull/324
Installation
From PyPi directly:
pip install kubernetes_asyncio
It requires Python 3.10+
Example
To list all pods:
import asyncio
from kubernetes_asyncio import client, config
from kubernetes_asyncio.client.api_client import ApiClient
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.
await config.load_kube_config()
# use the context manager to close http sessions automatically
async with ApiClient() as api:
v1 = client.CoreV1Api(api)
print("Listing pods with their IPs:")
ret = await v1.list_pod_for_all_namespaces()
for i in ret.items:
print(i.status.pod_ip, i.metadata.namespace, i.metadata.name)
if __name__ == "__main__":
asyncio.run(main())
More examples, including asynchronous multiple watch or tailing logs from pods,
can be found in examples/ folder.
Documentation
https://kubernetes-asyncio.readthedocs.io/
Microsoft Windows
In case this library is used against Kubernetes cluster using client-go credentials plugin, the default asyncio event loop is SelectorEventLoop. This event loop selector, however, does NOT support pipes and subprocesses, so exec_provider.py::ExecProvider is failing. In order to avoid failures the ProactorEventLoop has to be selected. The ProactorEventLoop can be enabled via WindowsProactorEventLoopPolicy.
Application's code needs to contain following code:
import asyncio
asyncio.set_event_loop_policy(
asyncio.WindowsProactorEventLoopPolicy()
)
Versions
This library is versioned in the same way as the synchronous library. The schema version has been changed with version v18.20.0. Now, first two numbers from version are Kubernetes version (v.1.18.20). The last number is for changes in the library not directly connected with K8s.
Development
# Create and activate virtual environment
uv venv
source .venv/bin/activate
# Install dependencies
uv sync
# Run ruff
ruff check .
ruff format --diff .
# Run tests
pytest
관련 프로젝트 살펴보기
불러오는 중…