I have a script which try to start subprocess with kubectl command like this:
params = [
"kubectl",
"get",
"svc",
"-o=jsonpath='{.items[*].spec.ports[*].port}'"
]
sp = subprocess.run(params, capture_output=True)
But I always get this error:
> raise child_exception_type(errno_num, err_msg, err_filename)
E FileNotFoundError: [Errno 2] No such file or directory: 'kubectl': 'kubectl'
/usr/lib/python3.7/subprocess.py:1522: FileNotFoundError
From pycharm terminal I can’t start kubectl too, but in my Linux terminal this work flawlessly without root user. User id for pycharm terminal and bash are same. How I can fix this problem?
I tried to move kubectl and helm into project and use "./kubectl" instead, this somewhat works, but I guess kubectl didn't manage to use its configs, because I get a connection error:
> raise ConnectionError(e, request=request)
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='host', port=8090): Max retries exceeded with url: /xss/1027019261true.1.php?test=%3Cscript%3Ealert(0);%3C/script%3E (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1daaf4b090>: Failed to establish a
new connection: [Errno 111] Connection refused'))
(host edited by me in question)
Try with the full path to kubectl binary.
I would use Kubernetes python client for any interactions with Kubernetes.