Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 如何在kubernetes上使用密码连接到psql_Postgresql_Kubernetes_Psql - Fatal编程技术网

Postgresql 如何在kubernetes上使用密码连接到psql

Postgresql 如何在kubernetes上使用密码连接到psql,postgresql,kubernetes,psql,Postgresql,Kubernetes,Psql,我想在kubernetes上使用kubectl exec命令上的密码连接到psql,如 kubectl exec-it postgres--bash\`psql-h$IP-U admin--password password-p$PORT dbname\` 我试着指挥 kubectl exec-it$podd--bash\`psql-h$IP-U admin--password-p$PORT postgresdb\` 及 kubectl exec-it$podd--bash-c“psql--

我想在kubernetes上使用
kubectl exec
命令上的密码连接到psql,如

kubectl exec-it postgres--bash\`psql-h$IP-U admin--password password-p$PORT dbname\`
我试着指挥

kubectl exec-it$podd--bash\`psql-h$IP-U admin--password-p$PORT postgresdb\`

kubectl exec-it$podd--bash-c“psql--dbname=postgresql://postgres:password@$ip:$port/postgresdb-c'插入公共。“用户”(用户id、用户pw、用户nm、电子邮件、电话、is_admin)值('admin'、'admin'、'admin'、'admin'、'admin@admin.com“,NULL,true);”
但这些命令并没有起作用

如何使用kubernetes命令和密码连接到psql?

您可以这样尝试:

kubectl exec-i--psql-h-u-p

由于您只需要命令,我假设您拥有所有部署、服务等

请执行下面的命令:

$ kubectl exec -ti <postgresspod-name> -- psql -h <node/host IP> -U postgresadmin --password -p <port> postgresdb
Password for user postgresadmin:
$kubectl exec-ti--psql-h-U postgresadmin--password-p postgresdb
用户postgresadmin的密码:
键入密码后,您将连接到Postgres

尝试
kubectl exec-it bash或sh

当您在容器内时,您只需执行
PGPASSWORD=psql-h-U

另一个选择是
kubectl exec-it postgres--bash\`PGPASSWORD=psql-h-U\`

这起到了作用:

kubectl  exec -ti postgres -- env PGPASSWORD=$PASSWD psql psql -h <host> -U <username> <dbname>
kubectl exec-ti postgres--env PGPASSWORD=$PASSWD psql psql-h-U
对我来说,只有这样才有效

kubectl exec postgres-postgresql-0 -n nte -- sh -c 'PGPASSWORD=postgres psql -U "postgres" -d "database_name" -c "select * from table_name"'
这不管用。“-p”选项表示端口号。。非密码