我正在尝试在kubernetes上部署spring boot应用程序并连接到本地主机上的postgres。
Spring启动部署很好。 对于我所做的Postgres
kind: Service
apiVersion: v1
metadata:
name: postgres
namespace: default
spec:
type: ExternalName
# https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
externalName: host.docker.internal
ports:
- name: port
port: 5432
kubectl get svc 提供
postgres ExternalName <none> host.docker.internal 5432/TCP 9m13s
我的数据库网址为
jdbc:postgresql://postgres:5432/postgres
因此,Spring Boot部署的日志将异常显示为
java.net.UnknownHostException: postgres
答案 0 :(得分:0)
此功能仅适用于Mac和Win Docker,因此,如果您在Linux上运行它-将无法使用。
此主机名已实现Linux支持,并且可能在接下来的几天/几周内推出:docker/libnetwork#2348
仍有一些变通办法,但尚未针对Linux发布
I。 您可以在项目中使用以下内容创建名为.ddev / docker-compose.xdebug.yaml的文件:
# For Linux users; Docker has not yet supported the "host.docker.internal"
# convention that is used in ddev v0.18.0. But if you add this file as
# .ddev/docker-compose.xdebug.yaml it should sort that out.
# Note that the IP address in your environment might not be 172.17.0.1,
# Find out what address to use with "ifconfig docker0" or "ip addr show docker0 | grep inet"
version: "3"
services:
web:
extra_hosts:
# Find out what address to use with "ifconfig docker0" or "ip addr show docker0 | grep inet"
- "host.docker.internal:172.17.0.1"
II。 使用此image将TCP和UDP流量转发到Docker主机