2020年12月22日星期二

Cannot stat: No such file or directory

I need to copy a file from a pod to the host by using kubernetes python client. I test the code from: https://github.com/prafull01/Kubernetes-Utilities/blob/master/kubectl_cp_as_python_client.py.

Specifically this code:

pod_name = 'koko-7768bff5d-8sw6z'  name_space = 'default'  # Copying file  source_path = '/tmp/hhss.txt'  destination_path = os.path.join(os.getcwd())  command_copy = ['tar', 'cf', '-', source_path]  with TemporaryFile() as tar_buffer:      exec_stream = stream(v2.connect_get_namespaced_pod_exec, pod_name, name_space,container='koko',                           command=command_copy, stderr=True, stdin=True, stdout=True, tty=False,                           _preload_content=False)      # Copy file to stream        try:          while exec_stream.is_open():              exec_stream.update(timeout=1)              if exec_stream.peek_stdout():                  out = exec_stream.read_stdout()                  tar_buffer.write(out.encode('utf-8'))              if exec_stream.peek_stderr():                  print("STDERR: %s" % exec_stream.read_stderr())          exec_stream.close()          tar_buffer.flush()          tar_buffer.seek(0)          with tarfile.open(fileobj=tar_buffer, mode='r:') as tar:              member = tar.getmember(source_path)              tar.makefile(member, destination_path)              return True      except Exception as e:          print(e)  

but I get error: Cannot stat: No such file or directory, like following:

enter image description here

then how to define correct source path? Here's what Happens when I enter the POD, showing the file path of the container specified in the POD.

enter image description here

https://stackoverflow.com/questions/65418374/cannot-stat-no-such-file-or-directory December 23, 2020 at 10:44AM

没有评论:

发表评论