使用集中的MySQL数据库开发ASP.NET Core 3.0应用程序。
我正在使用连接字符串,看起来像这样:
Server=mysql;Database=db-name;Uid=User;Pwd=Pass;SslMode=Preferred;persistsecurityinfo=false;
“ mysql”是一个内部DNS记录,它指向中央MySQL服务器。在Visual Studio中,它可以正常工作。
现在我想将其部署到kubernetes。
我已经使用MSSQL成功做到了。我在kubernetes中创建了一个端点(ep),指向正确的IP:
Name: mysql
Namespace: my_namespace
Labels: <none>
...
Subsets:
Addresses: 192.168.6.200
NotReadyAddresses: <none>
Ports:
Name Port Protocol
---- ---- --------
mysql 3306 TCP
Events: <none>
并且我创建了相应的Kubernetes服务:
Name: mysql
Namespace: my_namespace
Labels: <none>
...
Selector: <none>
Type: ClusterIP
IP: 10.104.84.99
Port: mysql 3306/TCP
TargetPort: 3306/TCP
Endpoints: 192.168.6.200:3306
Session Affinity: None
Events: <none>
所有这些看起来都像我使用MSSQL所做的一样。
而且我可以确认正在正常工作的网络:
root@kubernetes-server:/application# kv exec application-7c85b5d9d8-9vxhb -- curl mysql:3306
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0J
100 115 0 115 0 0 25 0 --:--:-- 0:00:04 --:--:-- 25#08S01Got packets out of order
“ Got数据包乱序”绝对是来自MySQL服务器的响应。我也可以通过Wireshark确认。
但是该应用程序将无法运行。我收到错误:"Unable to connect to any of the specified MySQL hosts."
我做错什么了吗?
问候,xola
知道了。不是连接字符串。不幸的是,我没有看到该错误消息上方的错误。由于我们对连接字符串进行了加密,因此我们具有用于解密的密钥。未正确设置解密密钥,因此应用程序希望使用加密的而不是解密的连接字符串来建立连接。
但是还是谢谢你!