k8s与运行中pod进行
我们要进入一个pod,并且执行一条命令,得到命令的返回值:
kubectl命令是:
kubectl exec -it calijob-159-element-attr-7z776 --namespace=calibration -- /bin/bash -c 'python3 /workspace/work.py -i 16'
python接口调度api是:
def pod_exec(self, name, namespace, command): exec_command = ["/bin/sh", "-c", command] resp = stream(self.core_v1.connect_get_namespaced_pod_exec, name, namespace, command=exec_command, stderr=True, stdin=False, stdout=True, tty=False, _preload_content=False) try: while resp.is_open(): resp.update(timeout=1) if resp.peek_stdout(): return resp.read_stdout() if resp.peek_stderr(): return resp.read_stderr() except Exception as e: ding_msg("pod exec exception:{}".format(e)) raise e finally: resp.close()
全世界的程序员们联合起来吧!