I have a Flask application getting launch with Gunicorn inside a Kubernetes pod with the following command:
exec gunicorn --log-file - --access-logfile - --access-logformat "${LOGFORMAT}" \
--no-sendfile -w 1 -t 600 --bind 0.0.0.0:${APIPORT-1380} ${EXTRABIND} ${ARGS} \
-n apiwrapper "apiwrapper:create_app()"
I want to attach the PTVSD debugger to my app and link it to VS Code. Here is the lines I added to my function create_app():
if os.getenv("DEV"):
import ptvsd
ptvsd.enable_attach(('0.0.0.0', 9797))
Our architecture is following this schema:
Ingress --> Service --> Pod
On my Kubernetes services I added:
- port: 9797
name: ptvsd-debugger
Which gives me:
backendapi ClusterIP x.x.35.83 <none> 80/TCP,1380/TCP,9797/TCP 81m
public-site-standard-web ClusterIP x.x.214.19 <none> 80/TCP,8080/TCP,9797/TCP 83m
And I added the following route to my two ingresses:
- path: /debugger
backend:
serviceName: backendapi
servicePort: 9797
NAME HOSTS ADDRESS PORTS AGE
public-site-standard-web jocteau.aws.citizennet.com 192.168.50.101 80, 443 3h42m
backendapi jocteau.aws.citizennet.com 192.168.50.101 80 3h40m
Here is the public-site Ingress:
Name: public-site-standard-web
Namespace: default
Address: 192.168.50.101
Default backend: default-http-backend:80 (<none>)
TLS:
dev-tls terminates myhostname.com
Rules:
Host Path Backends
---- ---- --------
myhostname.com
/debugger backendapi:9797 (x.x.x.25:9797)
/ public-site-standard-web:http (x.x.x.12:80)
and the backendapi Ingress:
Name: backendapi
Namespace: default
Address: 192.168.50.101
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
myhostname.com
/debugger backendapi:9797 (x.x.x.25:9797)
/backend/api/v2 backendapi:http (x.x.x.25:80)
So now I created my debugger config inside VS Code:
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 80,
"host": "myhostname.com/debugger",
"pathMappings": [
{
"localRoot": "${workspaceFolder}/backend/py",
"remoteRoot": "."
}
]
}
But I'm getting:
getaddrinfo ENOTFOUND myhostname.com/debugger
But when I try to access directly to the URL https://myhostname.com/debugger
I can see in my pod logs that my debugger is receiving the call:
E00139.153: Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/ptvsd/ipcjson.py", line 269, in process_one_message
msg = self.__message.pop(0)
IndexError: pop from empty list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/ptvsd/ipcjson.py", line 258, in process_messages
self.process_one_message()
......................
ptvsd.ipcjson.InvalidHeaderError: Malformed header, expected 'name: value'
What am I doing wrong with the VSCode configuration? Or is it impossible to do what I'm trying to achieve? Thank you