Is there a way to execute command within a pod using Openshift Python Client? #137
-
Hi, I'm trying to get ETCD Database size using the Python Client for OpenShift. I tried using subprocess.run, however due to a missing OC client on node side, the command fails. `from kubernetes import client, config, dynamic Script checking for ETCD DB Size.It will check for the cluster name and send info about current DB size of each ETCD Member.Mail templatedef send_mail(etcd_db): Authenticate against OCPwith open('/var/run/secrets/kubernetes.io/serviceaccount/token', 'r') as f: Get cluster name and set cname to = //v1_name = dyn_client.resources.get(api_version='v1', kind='ConfigMap') Check DB Size and send E-mailetcd_db = "oc exec -c etcdctl -n openshift-etcd -- etcdctl endpoint status -w table --cluster | awk '{print $8, $9}' | tail -n 4" Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @LiquIDMeowz, #!/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'Result:\n{result.out()}') |
Beta Was this translation helpful? Give feedback.
-
@bradmwilliams Hi, Thank you very much! |
Beta Was this translation helpful? Give feedback.
Hi @LiquIDMeowz,
Here is a script that should provide you a starting point for launching commands on a pod: