I want to connect to psql using password on kubectl exec
command on kubernetes like
kubectl exec -it postgres -- bash \`psql -h $IP -U admin --password password -p $PORT dbname\`
I tried to command
kubectl exec -it $podid -- bash \`psql -h $IP -U admin --password -p $PORT postgresdb\`
and
kubectl exec -it $podid -- bash -c "psql -- dbname=postgresql://postgres:password@$ip:$port/postgresdb -c 'INSERT INTO public."user" (user_id,user_pw,user_nm,email,phone,is_admin) VALUES ('admin','admin','admin','admin@admin.com',NULL,true);'"
but these command did not work.
How can I connect to psql using kubernetes commands and password?
As you asking only for command I assume you have all Deployments, Services, etc.
Please execute command below:
$ kubectl exec -ti <postgresspod-name> -- psql -h <node/host IP> -U postgresadmin --password -p <port> postgresdb
Password for user postgresadmin:
After you will type password you will be connected to Postgres
You can try this way :
kubectl exec -i <plsql podname> -- psql -h <host or service name or localhost> -u <username> -p<password>
trykubectl exec -it <postgresspod-name> bash or sh
when you inside the container you can just doPGPASSWORD=<password> psql -h <host or service name or localhost> -U <username> <dbname>
another option is kubectl exec -it postgres -- bash \`PGPASSWORD=<password> psql -h <host or service name or localhost> -U <username> <dbname>\`