我创建了一个自定义 SQL Server 数据库容器映像。我可以在我的本地机器上将它作为容器运行(Windows 10 和 Docker for Windows)。运行该容器后,我可以使用服务器名称作为 127.0.0.1:1433 从 SQL Server Management Studio 成功连接到它。
我正在尝试在 Azure 的 Kubernetes 中运行与 StatefulSet 相同的容器。
以下是 Kubernetes 资源。
机密(用于 SQL Server SA 密码)
apiVersion: v1
kind: Secret
metadata:
name: sqlsecret
type: Opaque
data:
sapassword: base64encodedvalue
存储类(StatefulSet - 外部存储)
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: azurestorageclass
provisioner: kubernetes.io/azure-disk
parameters:
skuName: Standard_LRS
location: southeastasia
storageAccount: myaccount
外部服务(也尝试过无头服务,但我还需要从 pod 外部连接)
apiVersion: v1
kind: Service
metadata:
name: sqlservice
labels:
name: sqlservice
spec:
ports:
- port: 1433
targetPort: 1433
externalIPs:
- Kubernetes-Cluster-LB-Public-IP-Address-From-Azure-Portal
selector:
role: sqlservice
最后是 StatefulSet。
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: sqlserverstatefulset
spec:
serviceName: "sqlservice"
replicas: 1
template:
metadata:
labels:
role: sqlservice
spec:
terminationGracePeriodSeconds: 10
containers:
- name: sqlinux
image: custom-image-from-docker-hub
env:
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: sqlsecret
key: sapassword
- name: ACCEPT_EULA
value: "Y"
ports:
- containerPort: 1433
volumeMounts:
- name: sql-persistent-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: sql-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "azurestorageclass"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 100Gi
我运行此命令以从我的本地计算机预配这些资源(上下文指向 Azure 集群)。
kubectl create -f c:\sqlkube.yaml
我的所有资源都已成功配置。Kubernetes 仪表板 ( kubctl proxy
) 中全是绿色,没有红色。
我还为端口 1433 设置了 Azure 负载均衡器的运行状况探测和负载均衡规则。
但是,当我在 SQL Server Management Studio 中输入 LB 的公共 IP 地址:1433 作为服务器名称时,出现以下错误。
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: 0 - The wait operation timed out.) (Microsoft SQL Server, Error: 258)
我错过了什么?