I am trying to execute the kubectl
command using python script but keep getting error. I have requirement to execute the kubectl
command to create pod and check the pod
log for any failure.
What am I doing wrong here?
import subprocess
command = 'kubectl apply -f deployment.yaml'
check_output= subprocess.check_output(command)
print(check_output)
error
Traceback (most recent call last):
File "/usr/bin/cma-scripts/kubectl.py", line 6, in <module>
check_output= subprocess.check_output(command)
File "/usr/local/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/local/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'kubectl apply -f deployment.yaml'