'Existing connection was forcibly closed by the remote host - Kubernetes
Im new into kubernetes and im following Les Jackson course about Microservices on YouTube. After i deployed the SQL server i cant connect to it using Management Studio. (Arround 5:30:00 on the course)
Here is the yaml code for deployment, its pretty much the same used on the course i just added some lines because i was getting and error "crashLoopBackOff" on the container:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mssql-depl
spec:
replicas: 1
selector:
matchLabels:
app: mssql
template:
metadata:
labels:
app: mssql
spec:
containers:
- name: mssql
image: mcr.microsoft.com/mssql/server:2019-latest
command: ["/bin/bash", "-c", "--"] #added this
args: ["while true; do sleep 30; done;"] #two lines
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Express"
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql
key: SA_PASSWORD
volumeMounts:
- mountPath: /var/opt/mssql/data
name: mssqldb
volumes:
- name: mssqldb
persistentVolumeClaim:
claimName: mssql-claim
---
apiVersion: v1
kind: Service
metadata:
name: mssql-clusterip-srv
spec:
type: ClusterIP
selector:
app: mssql
ports:
- name: mssql
protocol: TCP
port: 1433
targetPort: 1433
---
apiVersion: v1
kind: Service
metadata:
name: mssql-loadbalancer
spec:
type: LoadBalancer
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
Thanks!
Solution 1:[1]
Well, after several attempts to recreate your situation completely, I managed to do it. I have encountered several problems, the solution of which I will describe below. From the input parameters I have Windows 10 pro, installed Docker desktop, and Kubernetes v1.22.5. Also 2 files pvc.yaml and deployment.yaml.
- We'll start by deleting all the previous Clusters and Nodes to start all over again. And at the end, reboot your system.
# Write neme of your config files
kubectl delete -f pvc.yaml
kubectl delete -f deployment.yaml
- After that, launch
Docker desktopand in theSettingstab, selectKubernetesand start it. - Launch a command-line terminal, navigate to the directory with your files and run the command:
kubectl create -f pvc.yaml
Where the configuration will be:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mssql-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 200Mi
Run next command to create a secret:
kubectl create secret generic mssql5 --from-literal=SA_PASSWORD="MyC0m9l&xPassw0rd"
Run last command:
kubectl create -f deployment.yaml
With configuration:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mssql-depl
spec:
replicas: 1
selector:
matchLabels:
app: mssql
template:
metadata:
labels:
app: mssql
spec:
containers:
- name: mssql
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Express"
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql5
key: SA_PASSWORD
volumeMounts:
- mountPath: /var/opt/mssql/data
name: mssqldb
volumes:
- name: mssqldb
persistentVolumeClaim:
claimName: mssql-claim
---
apiVersion: v1
kind: Service
metadata:
name: mssql-clusterip-srv
spec:
type: ClusterIP
selector:
app: mssql
ports:
- name: mssql
protocol: TCP
port: 1433
targetPort: 1433
---
apiVersion: v1
kind: Service
metadata:
name: mssql-loadbalancer
spec:
type: LoadBalancer
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
- After your cluster and services start, check them using the commands
kubectl get pods,kubectl get services. If everything is ok and you see the output from the screenshot below.
- You can proceed to checking your secret file by following the documentation run command:
kubectl edit secrets mysecret
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
SA_PASSWORD: TXlDMG05bCZ4UGFzc3cwcmQ= # << ERROR
kind: Secret
metadata:
creationTimestamp: "2022-03-23T17:31:31Z"
name: mssql5
namespace: default
resourceVersion: "633"
uid: 62184a05-7641-4296-944f-4e9a149e5bb5
type: Opaque
- My password was different from the password I created. If you have also then edit the file and restart services. After that you can connect to your
SQL Server. - If the problem continues, you can connect with
Windows Authentication, then clickSecurity>Logins>Propertieson your username right mouse button >Propertiesand change password there.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mykola |




