How do I build kubernetes-client/python?

To build kubernetes-client/python, utilize the following steps and code snippets.

  1. Install Dependencies: Ensure the environment meets the Python requirement, which can be Python 2.7 or 3.5 and above.

  2. Cloning the Repository: Clone the repository using the following command:

    git clone --recursive https://github.com/kubernetes-client/python.git
    
  3. Navigating to the Directory: Change into the cloned directory:

    cd python
    
  4. Installing with pip: If you wish to install directly from the repository, use:

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

    Note: Performing this command may require root permissions; use sudo if necessary.

  5. Installing via Setuptools: Alternatively, you can install the client using Setuptools:

    python setup.py install --user
    

    For a system-wide installation:

    sudo python setup.py install
    
  6. Importing the Kubernetes Client: After the successful installation, you can import the Kubernetes client in your Python scripts:

    import kubernetes.client
    
  7. Running Examples: The repository contains example scripts that can be executed to test the installation:

    python -m examples.example1
    

    Replace example1 with the name of the desired example script in the examples folder.

  8. Configuration Example: To configure and use the Kubernetes API, you can follow this code snippet:

    from __future__ import print_function
    import time
    import kubernetes.client
    from kubernetes.client.rest import ApiException
    from pprint import pprint
    
    

    configuration = kubernetes.client.Configuration()

    Configure API key authorization: BearerToken

    configuration.api_key['authorization'] = 'YOUR_API_KEY'

    Uncomment below to setup prefix (e.g. Bearer) for API key, if needed

    configuration.api_key_prefix['authorization'] = 'Bearer'

    Defining host is optional and default to http://localhost

    configuration.host = "http://localhost"

Refer to the sources for more detailed installation instructions and additional configuration options as needed.