首页 > 解决方案 > 无法从 Azure Kubernetes 服务连接到 Azure SQL DB 服务器

问题描述

我正在尝试在 Azure Kubernetes 中部署 ASP .Net Core Web API 3.0。我的 Dot Net Core Web API 连接到 Azure SQL 数据库。下面是配置

连接字符串

"ConnectionString": "Server=myservername,1433;Initial Catalog=mydbname;Persist Security Info=False;User ID=userid;Password=*******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

部署和服务 yaml 文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-api
  labels:
    app: my-web-api
spec:
  replicas: 2
  minReadySeconds: 45
  selector:
    matchLabels:
      app: my-web-api
  strategy:
    rollingUpdate:
        maxSurge: 25%
        maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: my-web-api
    spec:
      containers:
        - name: my-web-api
          image: myazureregistry/myapi:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 80
            - containerPort: 443
            - containerPort: 1433
      volumes:
      - name: secrets
        secret:
          secretName: secret-appsettings1
---
apiVersion: v1
kind: Service
metadata:
  name: my-web-api
  labels:
    app: my-web-api
spec:
  type: LoadBalancer
  ports:
    - name: port-8080
      port: 8080
      targetPort: 80
    - name: port-1433
      port: 1433
      targetPort: 1433
  selector:
    app: my-web-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: TCP Provider, error: 40 - Could not open a connection to SQL Server)

我是 AKS 和 Kubernetes 的新手。请问有人可以为此提供解决方案吗?

标签: azurekubernetes

解决方案


推荐阅读