def kubectl ( * args , input = None , * * flags ) : # Build command line call. line = [ 'kubectl' ] + list ( args ) line = line + get_flag_args ( * * flags ) if input is not None : line = line + [ '-f' , '-' ] # Run subprocess output = subprocess . run ( line , input = input , capture_output = True , text = True ) return output
kubectl api for python
Simple wrapper to kubectl .
def kubectl(*args, input=None, **flags):
    """Simple wrapper to kubectl."""
    # Build command line call.
    line = ['kubectl'] + list(args)
    line = line + get_flag_args(**flags)
    if input is not None:
        line = line + ['-f', '-']
    # Run subprocess
    output = subprocess.run(
        line,
        input=input,
        capture_output=True,
        text=True
    )
    return output