Kubernetes 建立与 SQL 服务器的连接时出现与网络相关或特定于实例的错误

Kubernetes A network-related or instance-specific error occurred while establishing a connection to SQL Server

我在 kubernetes 上有 docker 和 运行,该站点可以从浏览器浏览。执行请求 API 时,需要连接到数据库。 数据库托管在 SQL Azure 上,而不是另一个 docker.

我遇到了这个错误

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

如何排查和解决问题?

我发现了问题,问题是 dockerFile connectionString 仍在使用 appsettings.json 中的那个。

这样的环境我过了

kubectl run identityapi --image xxxxxxxx.azurecr.io/panda/identity.api --port=80 --env="ASPNETCORE_ENVIRONMENT=Development" --env="ConnectionStrings__DefaultConnection=Server=xxxxxxxx.database.windows.net,1433;Initial Catalog=panda.identity;Persist Security Info=False;User ID=xxxxxxxx;Password=xxxxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

ConnectionStrings__DefaultConnection 的环境必须使用双下划线而不是点 (.)