'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)

As you can see SQL container is running

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

Pod description: enter image description here

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.

  1. 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
  1. After that, launch Docker desktop and in the Settings tab, select Kubernetes and start it.
  2. 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
  1. 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.

enter image description here

  1. 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
  1. 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.
  2. If the problem continues, you can connect with Windows Authentication, then click Security > Logins > Properties on your username right mouse button > Properties and change password there.

enter image description here

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