在本地开发环境 (Ubuntu) 上安装了 Docker 和 Minishift。
使用 Docker 启动一个带有 mariadb:10.3.11 的容器:
docker run -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 --name mariadb 4f2e75647d2a
从主机系统运行 curl 具有以下输出:
curl 172.17.0.1:3306
curl: (56) Recv failure: Connection reset by peer
5.5.5-10.3.11-MariaDB-1:10.3.11+maria~bionic
QpatFAPM���rv{(RC:7G@H+mysql_native_password!��#08S01Got packets out of order%
目标是从运行在 Minishift 中的 pod 连接到这个 MariaDB。我遵循了本教程:https ://docs.okd.io/latest/dev_guide/integrating_external_services.html
apiVersion: v1
kind: List
items:
- kind: "Service"
apiVersion: "v1"
metadata:
name: "external-mysql-service"
spec:
ports:
- name: "mysql"
protocol: "TCP"
port: 3306
targetPort: 3306
nodePort: 0
selector: {}
- kind: "Endpoints"
apiVersion: "v1"
metadata:
name: "external-mysql-service"
subsets:
- addresses:
- ip: "172.17.0.1"
ports:
- port: 3306
name: "mysql"
但是,pod 无法连接到 MariaDB,并出现以下错误:
2019-02-19 18:00:42 [ERROR] HikariPool:567 - HikariPool-1 - Exception during pool initialization.
java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=external-mysql-service)(port=3306)(type=master) : Connection refused (Connection refused)
如果我通过 OpenShift Web 控制台中的终端选项卡连接到 pod 并尝试
$ curl -v external-mysql-service:3306
* Rebuilt URL to: external-mysql-service:3306/
* Trying 172.30.23.62...
* TCP_NODELAY set
* connect to 172.30.23.62 port 3306 failed: Connection refused
* Failed to connect to external-mysql-service port 3306: Connection refused
* Closing connection 0
curl: (7) Failed to connect to external-mysql-service port 3306: Connection refused
如何建立从 Minishift pod 到 Docker 容器的连接?
总体目标是使用任意外部服务。