Skip to content

Is there a way to execute command within a pod using Openshift Python Client? #137

Closed Answered by bradmwilliams
LiquIDMeowz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @LiquIDMeowz,
Here is a script that should provide you a starting point for launching commands on a pod:

#!/usr/bin/python

import openshift as oc

if __name__ == '__main__':
    options = {
        'as': 'system:admin',
        'context': 'my_cluster_1',
    }

    with oc.client_host():
        with oc.timeout(60 * 5):
            with oc.options(options):
                with oc.project("openshift-etcd"):
                    pods = oc.selector("pods", labels={'app': 'etcd'}).objects()
                    print(f'Found: {len(pods)} pods')
                    result = pods[0].execute(cmd_to_exec=['etcdctl', 'endpoint', 'status', '--cluster', '-w', 'table'])
                    print(f…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@bradmwilliams
Comment options

Answer selected by LiquIDMeowz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants