minikube中arango-single-server无法通过arangosh连接问题排查
ArangoDB单实例Kubectl exec连接失败排查
问题场景
在minikube环境中部署arango-single-server,按官方流程通过kubectl完成安装后,执行容器内arangosh命令连接数据库时失败,但可正常访问GUI管理界面。
连接命令及错误输出
➜ kubectl exec -it arango-single-server-sngl-d0leq3in-d9649f -- arangosh --server.endpoint "tcp://localhost:8529" --server.database "_system" Defaulted container "server" out of: server, init-lifecycle (init), uuid (init) Please specify a password: _ __ _ _ __ __ _ _ __ __ _ ___ ___| |__ / _` | '__/ _` | '_ \ / _` |/ _ \/ __| '_ \ | (_| | | | (_| | | | | (_| | (_) \__ \ | | | \__,_|_| \__,_|_| |_|\__, |\___/|___/_| |_| |___/ arangosh (ArangoDB 3.9.3 [linux] 64bit, using jemalloc, build tags/v3.9.3-0-gb9cd8359a1a, VPack 0.1.35, RocksDB 6.27.0, ICU 64.2, V8 7.9.317, OpenSSL 1.1.1q 5 Jul 2022) Copyright (c) ArangoDB GmbH Command-line history will be persisted when the shell is exited. You can use `--console.history false` to turn this off Could not connect to endpoint 'tcp://localhost:8529', database: '_system', username: 'root' Error message: 'Connection closed' localhost:8529@_system>
容器内端口监听状态(netstat输出)
➜ kubectl exec -it arango-single-server-sngl-d0leq3in-d9649f -- netstat -a Defaulted container "server" out of: server, init-lifecycle (init), uuid (init) Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:56568 localhost:8529 ESTABLISHED tcp 0 0 :::8529 :::* LISTEN tcp 0 0 localhost:8529 localhost:56568 ESTABLISHED Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 3 [ ] DGRAM 3845565 unix 3 [ ] DGRAM 3845564
问题原因
从netstat结果可见,ArangoDB仅在**IPv6任意地址(:::8529)**上监听,而你使用的tcp://localhost:8529默认解析为IPv4的127.0.0.1,容器内的ArangoDB未在IPv4端口监听,导致连接请求被直接关闭。
GUI能正常访问是因为外部请求通过Kubernetes Service转发,Service会自动处理IPv4/IPv6的地址映射;而容器内直接连接时没有这个转发层,因此出现访问差异。
解决办法
方法1:直接使用IPv6本地地址连接
修改arangosh的连接端点为IPv6格式的localhost,执行命令:
kubectl exec -it arango-single-server-sngl-d0leq3in-d9649f -- arangosh --server.endpoint "tcp://[::1]:8529" --server.database "_system"
方法2:配置ArangoDB同时监听IPv4和IPv6
修改ArangoDB的Deployment配置,添加启动参数让服务同时监听双栈地址:
- 编辑Deployment:
kubectl edit deployment arango-single-server-sngl
- 在容器的
args列表中添加--server.endpoint tcp://0.0.0.0:8529,此参数会让服务同时监听IPv4的0.0.0.0和IPv6的::地址 - 保存退出后,等待Pod重启完成,即可用原
tcp://localhost:8529地址连接
内容的提问来源于stack exchange,提问作者Faaiz
相关产品推荐
相关产品推荐

