google-cloud-platformredisgoogle-kubernetes-engineportforwarding

Not able to port forward from local to redis server in wrokload in GCP


I am trying to connect to redis cache in dev server which is a pod in GCP. we are trying to connect it through a proxy server using below command

gcloud beta compute ssh --zone "<zone>" "proxy-server" --project "project-name" --internal-ip --ssh-flag="-NL <local_port>:<redis-server-ip>:<port>"

but its throwing error in google cloud console installed in my windows system error is 'unknown option "-NL"'

ERROR: (gcloud.compute.beta.ssh) [C:\Users\<user-dir>\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\sdk\putty.exe] exited with return code [1].

but its running fine in mac, please help me in resolving the issue at the earliest.

As suggested by one of the answer, tried running below command

kubectl port-forward pod/pod-58759-s4wfz 6377:6379

getting this error now:

C:\Windows\system32>kubectl port-forward pod/pod-587597c46d-s4wfz 6377:6379
Forwarding from 127.0.0.1:6377 -> 6379
Forwarding from [::1]:6377 -> 6379
Handling connection for 6377
E0120 12:34:32.504209   18476 portforward.go:406] an error occurred forwarding 6377 -> 6379: error forwarding port 6379 to pod a5bba767d7ec94aaf, uid : exit status 1: 2022/01/20 07:04:34 socat[910] E connect(5, AF=2 127.0.0.1:6379, 16): Connection refused
E0120 12:34:32.508193   18476 portforward.go:234] lost connection to pod

Thanks


Solution

  • After 1 day of effort I found an answer which corrected my command, just need to use below command, in place of -NL we should use -N -L in windows

    gcloud beta compute ssh --zone "<zone>" "proxy-server" --project "project-name" --internal-ip -- -N -L <local_port>:<redis-server-ip>:<port>