AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-430806

Chayan Ghosh's questions

Martin Hope
Chayan Ghosh
Asked: 2021-06-07 21:55:14 +0800 CST

双端口转发kubernetes + docker

  • 0

概括:

我有一个运行 kubectl port-forward 的 docker 容器,它将作为 k8s 服务运行的 postgres 服务的端口(5432)转发到本地端口(2223)。在 Dockerfile 中,我已经暴露了相关的 2223 端口。然后我通过发布所述端口 ( -p 2223:2223)来运行容器

现在,当我尝试通过 访问 postgrespsql -h localhost -p 2223时,出现以下错误:

psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

但是,当我docker exec -ti对上述容器执行上述操作并运行上述 psql 命令时,我可以连接到 postgres。

Dockerfile 命令:

EXPOSE 2223
CMD ["bash", "-c", "kubectl -n namespace_test port-forward service/postgres-11-2 2223:5432"]

Docker 运行命令:

docker run -it --name=k8s-conn-12 -p 2223:2223 my_image_name:latest

docker run 命令的输出:

Forwarding from 127.0.0.1:2223 -> 5432

所以端口转发成功,我可以从 docker 容器内部连接到 postgres 实例。我不能做的是从容器外部连接到暴露和发布的端口

port-forwarding docker kubernetes kubectl psql
  • 1 个回答
  • 1188 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve