microsoft / mindaro

Bridge to Kubernetes - for Visual Studio and Visual Studio Code
MIT License
307 stars 106 forks source link

Failed to connect to sqlserver while running eshopondapr using bridge to k8s #244

Open starryrbs opened 2 years ago

starryrbs commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

Failed to connect to sqlserver while running eshopondapr using bridge to k8s. The following error was encountered.

[15:23:42 FTL] Host terminated unexpectedly (Catalog.API)... Microsoft.Data.SqlClient.SqlException (0x80131904): 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (53): 找不到网络路径。

To Reproduce Steps to follow to reproduce this issue.

clone code

git clone https://github.com/dotnet-architecture/eShopOnContainers

Deploy applications in the K8S cluster

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Catalog API Launch (web) with Kubernetes",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "bridge-to-kubernetes.compound",
            "program": "${workspaceFolder}/src/Services/Catalog/Catalog.API/bin/Debug/netcoreapp5.0/Catalog.API.dll",
            "args": [],
            "cwd": "${workspaceFolder}/src/Services/Catalog/Catalog.API",
            "stopAtEntry": false,
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS": "http://+:3001"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "bridge-to-kubernetes.resource",
            "type": "bridge-to-kubernetes.resource",
            "resource": "catalog-api",
            "resourceType": "service",
            "ports": [
                3500
            ],
            "targetCluster": "kubernetes",
            "targetNamespace": "eshopondapr",
            "useKubernetesServiceEnvironmentVariables": false
        },
        {
            "label": "bridge-to-kubernetes.compound",
            "dependsOn": [
                "bridge-to-kubernetes.resource",
                "build"
            ],
            "dependsOrder": "sequence"
        }
    ]
}

Run Catalog API Launch (web) with Kubernetes

**Expected behavior** A clear and concise description of what you expected to happen. **Logs** Attach logs from the following directory: For Windows: %TEMP%/Bridge to Kubernetes For OSX/Linux: $TMPDIR/Bridge to Kubernetes If you are a Visual Studio user, - Set the environment variable MS_VS_AZUREDEVSPACES_TOOLS_LOGGING_ENABLED=true - Open Visual Studio and run your scenario - Provide logs from: %temp%\Microsoft.VisualStudio.Kubernetes.Debugging **Environment Details** Client used (VS Code/Visual Studio): Client's version: Operating System: **Additional context** Add any other outputs from the clients or context you would like to share.
rakeshvanga commented 2 years ago

Hi @starryrbs We have not test Bridge to Kubernetes on the sample app you've shared. From the error message you've shared, the SQL server might not allow connection from your local dev box. Can you try to connect to SQL server from your dev box?

starryrbs commented 2 years ago

I confirm that the SQL server is available on my development machine. I use the following command:

kubectl port-forward deployment/sqldata -n eshopondapr 7888:1433 --address 0.0.0.0

On my development machine, it can be connected.

Using the connection string "Server=sqldata;Database=Microsoft.eShopOnDapr.Services.CatalogDb;User Id=sa;Password=Pass@word" in my application fails to connect.

In the database-api sample project, I was able to connect to MongoDB normally.

I have tried many times, but it still doesn't work. Can you help me find out what the problem is?

rakeshvanga commented 2 years ago

@starryrbs Thanks for the details. It seems that you are trying to connect to sql server using port-forward. Can you try to connect directly without using port-forward?

Also, I will try out the sample application you've shared to understand the issue you are facing.

starryrbs commented 2 years ago

I tried to use sqldata on my machine to connect, but could not connect. image

I looked at the run log. image There are no changes to the hosts file. However, using database-api updates the hosts file.

This is a DAPR app. I tried the dapr supported version and reported the same error. https://github.com/microsoft/mindaro/issues/195#issuecomment-872663727

This is the log of the pod that failed to start on the kube cluster. pod.log

In addition, thank you very much for your reply, @rakeshvanga.