postgresql - 用于从外部 AKS 访问 postgres 的 Port-foward 命令在 kubectl 中由于 & 符号而无法工作
问题描述
我正在尝试从以下 Bitnami 图表在 AKS 上部署 PostgreSQL:https ://github.com/bitnami/charts/tree/master/upstreamed/postgresql/#installing-the-chart
在部署期间,我被邀请使用以下命令(一旦安装)以确保我能够访问集群外部的 postgres(例如一些本地 DBMS)
kubectl port-forward --namespace default svc/dozing-coral-postgresql 5432:5432 & PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -p 5432
这会导致语法错误:
At line:1 char:80
+ ... d --namespace default svc/dozing-coral-postgresql 5432:5432 & PGPASSW
...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for
future use; wrap an ampersand in double quotation marks ("&") to pass it as
part of a string.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : AmpersandNotAllowed
解锁端口的正确命令是什么?
解决方案
您应该看到的输出类似于
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
有两种不同的命令。第一个是转发端口,最后&
是将此命令发送到后台,以便您能够继续使用shell
$ kubectl port-forward --namespace default svc/jolly-raccoon-postgresql 5432:5432 &
[1] 62447
Forwarding from 127.0.0.1:5432 -> 5432
第二个命令允许您使用已安装psql
客户端的另一台主机的转发端口连接到数据库
$ PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -p 5432
psql (11.3)
Type "help" for help.
postgres=#
推荐阅读
- azure - 遇到混合连接异常:所有连接的侦听器均未在允许的超时时间内接受连接
- android - FirebaseRecyclerAdapter 不显示来自 notifyDataSetChanged() 的更改
- javascript - 在 HTML 文件的标头中的源源下运行 JavaScript 文件
- javascript - 将字符串导出到文件中而不解释 `${process.env.REACT_APP_ENV}`
- php - 在 EventSubscriber 中如何从 URL 获取参数?
- python - 如何使用 pyqt5 捕获图像?
- f# - 参数化异常类型
- c - 为什么使用 GDB 检查时,某些局部变量没有在相应的堆栈帧中列出?
- r - 将回归系数存储在 R data.table 中
- pic - 如何定义 Rb0 到 Rb6 = hex (x%10); // 没有 Rb7 引脚