I have a k8s deployment that contains a docker image that's running a jar that is supposed to have one HTTP 3000 port and a WebSocket 8982 port exposed.
When I run the standalone jar locally, I can communicate with those ports using curl and a WebSocket client.
I create a proxy using kubectl proxy
, and go to this address:
http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/
However, this request returns:
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "error trying to reach service: dial tcp 10.244.0.5:80: connect: connection refused",
"code": 500
}
How do I access those two ports in my pod that's running the deployment?
you can use the command kubectl port-forward
it will work like same way and create a proxy tunnel between local and cluster
for example, if you service name is test-service
kubectl port-forward svc/test-service 8080:3000
this will create the tunnel local to cluster where the local port will be 8080 and service port will be 3000 and service will route traffic to container or pod.
Read more at : https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/
kubectl proxy
for managing or connecting with the Kubernetes API server and use the admin APIs.
if you don't have the service you can directly proxy the traffic to POD from local
Listen on port 8888 locally, forwarding to 3000 in the pod
kubectl port-forward pod/<POD NAME> 8888:3000