Port-foward command to access postgres from outside AKS not working in kubectl due to ampersand
The output you should see is something like
To connect to your database from outside the cluster execute the following commands: kubectl port-forward --namespace default svc/jolly-raccoon-postgresql 5432:5432 & PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -p 5432
There are two different commands. The first one is to forward the ports, and the final &
is to send this command to the background so you are able to continue using the shell
$ kubectl port-forward --namespace default svc/jolly-raccoon-postgresql 5432:5432 &[1] 62447Forwarding from 127.0.0.1:5432 -> 5432
The second command allows you to connect to the database using the forwarded port from another host where you have installed the psql
client
$ PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -p 5432psql (11.3)Type "help" for help.postgres=#