Search code examples
pythonkuberneteskubernetes-helm

Run Helm commands using python script


I wanted to run "helm repo add datawire https://app.getambassador.io " using python scripts. I researched and found this link https://github.com/andriisoldatenko/pyhelm/blob/master/pyhelm/repo.py. But I didn't find that I needed. Could you help me with that ?


Solution

  • If you want to run commands with Python, the best way is to use subprocess, it's very easy and works great, usually.

    Here's an example:

    import subprocess
    
    subprocess.check_call(['helm',  'repo' 'add', 'datawire', 'https://app.getambassador.io/'])
    

    Notice that this will just call the helm client and wait for it to complete. If the command which you started returns with error, then an Exception will be thrown.

    If you need the stdout output of the command, you can instead use check_output.


    Subprocess documentation can be found here