user1477747
user1477747

Reputation: 39

Impossible connect to sql server container locally with Minikube

i'm trying to test locally some microservices .NET Core with Minikube. I've 2 microservices that comunicate with each other and with a container with mssql by clusterIP. It works all fine, but i can't connect directly to mssql from SQL Management Studio.

Here the deployment of mssql:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mssql-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mssql
  template:
    metadata:
      labels:
        app: mssql
    spec:
      containers:
      - name: mssql
        image: mcr.microsoft.com/mssql/server:2017-latest
        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-service
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

I've tried also with NodePort but i can't access it by "localhost, 1433" Any idea of how can i access it externally?

Thanks

Upvotes: 0

Views: 1537

Answers (2)

csharp.janari
csharp.janari

Reputation: 1

I watched Les Jacksons cource too) And had same issue you need to do :

minikube ip

Write it in cmd with Admin role, you will get the minikube ip, after that:

kubectl get svc
NAME                      TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
mssql-clusterip-srv       ClusterIP      10.98.79.121     <none>        1433/TCP         46m
mssql-loadbalancer        LoadBalancer   10.110.176.240   <pending>     1433:32509/TCP   46m

Here you have your loadBalancer service, you need to use external port for connecting with Sql Server(External port in my case is 32509 and this post will redirect it to 1433 port)

server name will be: your_minikube_ip, loadBalancer_external_port

I hope it will work for you

Upvotes: 0

There is a different way to access your app from external world. If you use the LoadBalancer type service then you can do the following steps to access your app from external(for only minikube):

  1. Run the below command in different terminal:
minikube tunnel
  1. Get the services
kubectl get svc

The output looks like:

$ kubectl get svc
NAME                 TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
kubernetes           ClusterIP      10.96.0.1       <none>          443/TCP          20m
mssql-loadbalancer   LoadBalancer   10.102.149.78   10.102.149.78   1433:30373/TCP   16s
  1. open in your browser (make sure there is no proxy set)
http://REPLACE_WITH_EXTERNAL_IP:1443

You can also use a port-forwarding mechanism to access your app like:

kubectl port-forward service/<your service> 1443:1443

Ref: https://minikube.sigs.k8s.io/docs/handbook/accessing/

Upvotes: 1

Related Questions