Kubernetes Python Client

repository·master·Indexed 27 days ago

https://github.com/kubernetes-client/python

Official client library for interacting with the Kubernetes API, providing both synchronous and asynchronous (asyncio) interfaces. It includes support for managing core resources (Pods, Services, Namespaces), Apps API (Deployments, StatefulSets), Autoscaling, Batch, and Custom Resource Definitions (CRDs) via classes such as CoreV1Api, AppsV1Api, and CustomObjectsApi.

Tokens
186.1K
Snippets
177
Records
366
Agent score
88%

What's inside kubernetes-client-python

  1. Use kubernetes.aio.client for asynchronous Kubernetes API interaction

    master
    The kubernetes.aio.client module provides an asynchronous interface for interacting with the Kubernetes API. It requires proper configuration of authentication and authorization parameters to match your API server's security policy. When using the client, it is recommended to use a context manager to ensure that HTTP sessions are closed automatically.
  2. Use kubernetes.aio.client for asynchronous Kubernetes API operations

    master

    The kubernetes.aio.client provides an asynchronous interface for interacting with the Kubernetes API. This is useful for high-concurrency applications or when integrating with other asyncio-based libraries.

    When using the asynchronous client, ensure you configure authentication and authorization parameters according to your API server's security policy. The host parameter is optional and defaults to http://localhost.

  3. Configure BearerToken API Key Authorization

    master

    To authenticate with the Kubernetes API using a Bearer Token, configure the api_key dictionary in the Configuration object using the key 'BearerToken'. If your API server requires the Bearer prefix, you must also set the api_key_prefix for that key.

    configuration = kubernetes.aio.client.Configuration(host="http://localhost")
    
    # Set the token
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # Set the prefix if required (e.g., 'Bearer')
    configuration.api_key_prefix['BearerToken'] = 'Bearer'
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
  4. Install the kubernetes.aio.client package

    master

    You can install the asynchronous Kubernetes Python client using pip directly from the GitHub repository or via setuptools.

    Using pip:

    pip install git+https://github.com/kubernetes-kubernetes.aio.client/python.git

    (Note: You may need sudo for system-wide installation).

    Using Setuptools:

    python setup.py install --user
    pip install git+https://github.com/kubernetes-kubernetes.aio.client/python.git
  5. Configure BearerToken authentication for AdmissionregistrationV1beta1Api

    master

    To use BearerToken authentication with the AdmissionregistrationV1beta1Api, configure the Configuration object by setting the api_key for 'BearerToken'. If your API server requires a prefix (like Bearer ), you must also set the api_key_prefix.

    configuration = kubernetes.aio.client.Configuration(
        host = "http://localhost"
    )
    
    # Configure API key authorization: BearerToken
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
  6. Configure BearerToken authentication for AppsV1Api

    master

    To use BearerToken authentication with the kubernetes.aio.client, you must configure the api_key and optionally the api_key_prefix in the Configuration object.

    configuration = kubernetes.aio.client.Configuration(host="http://localhost")
    
    # Set the token
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # If the API server requires the 'Bearer ' prefix, uncomment the line below
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
  7. Configure BearerToken Authentication for kubernetes.aio.client

    master

    To use BearerToken authentication with the asynchronous Kubernetes client, configure the Configuration object by setting the api_key for the BearerToken key. If your API server requires a prefix (like Bearer ), you must also set the api_key_prefix.

    configuration = kubernetes.aio.client.Configuration(
        host = "http://localhost"
    )
    
    # Configure API key authorization: BearerToken
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
    configuration.api_key_prefix['BearerToken'] = 'Bearer'
  8. Configure BearerToken Authentication for AdmissionregistrationV1alpha1Api

    master

    To use BearerToken authentication with the AdmissionregistrationV1alpha1Api, configure the api_key and optionally the api_key_prefix in the Configuration object.

    configuration = kubernetes.aio.client.Configuration(host="http://localhost")
    
    # Set the token
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # If the API server requires the 'Bearer ' prefix, uncomment the line below
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
  9. Configure BearerToken Authentication

    master

    To use BearerToken authentication with the kubernetes.aio.client, configure the api_key and optionally the api_key_prefix in the Configuration object.

    configuration = kubernetes.aio.client.Configuration(host="http://localhost")
    
    # Set the token
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # If the server expects 'Bearer <token>', set the prefix
    configuration.api_key_prefix['BearerToken'] = 'Bearer'
    configuration.api_key['BearerToken'] = 'YOUR_API_KEY'
    
    # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
    # configuration.api_key_prefix['BearerToken'] = 'Bearer'
  10. Configure Authentication and Authorization

    master
    The Kubernetes Python client requires authentication and authorization parameters to be configured in accordance with your API server's security policy. You can set these configurations directly in the Configuration class or use helper utilities. If no specific host is provided, the client defaults to http://localhost.