Issues with Connecting to my Database in Preview Environment Using Port Forwarding?

Hi all,

I’m trying to follow the instructions in this blog post, Connecting to your Databases using Port Forwarding but am running into issues getting the connection established. My situation is as follows:

  • I’ve got a MySQL instance running in a Preview Environment on Okteto Cloud
  • On the CLI, I ran
    • okteto namespace
    • okteto kubeconfig
    • kubectl port-forward service/<SERVICE_NAME> 3306:3306

However, I still get this error and am not sure where I am going wrong:

error: timed out waiting for the condition

I ran kubectl get svc and am able to see the running service listed, so I believe the connection is working.

Does anybody have any idea what could be going wrong? Any advice would be much appreciated, thanks!

Hi @justinjao ! I haven’t been able to reproduce it. What happens if you do the port forward to the pod instead of to the service?

Something else to try is to pass the namespace explicitly to the port-forward command: kubectl port-forward -n=<NAMESPACE_NAME> service/<SERVICE_NAME> 3306:3306

(in the case of preview environments, the namespace is the name of the preview environment)

FWIW, I deployed GitHub - okteto/go-todo-list: Sample of how to develop a multi-tier application with okteto on my account and I was able to set a port-forward to the DB

$ okteto context use
$ okteto kubeconfig
$ kubectl --namespace $NAMESPACE port-forward svc/db 5432:5432
Forwarding from -> 5432
Forwarding from [::1]:5432 -> 5432

Hi @ramiro, that was it, passing the namespace beforehand worked! Thank you for your help!