I have an external SQL server, (On the Internet accessible from my local system) that I am trying to call from inside the Minikube. I am unable to do that. I have tried the Calling an external service from within Minikube
Error that i am getting is "sqlalchemy.exc.OperationalError: (pymssql.OperationalError) (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist "
I have already created pod --> service --> Endpoints. All my Clusters are under an ingress. Please see the below code for the configuration that I have done.
Currently, I am passing the DB HOST (1.1.1.1) as an environment variable to the POD and after this configuration, I am trying to pass the service name (sql-server) instead of DB Host Name is this correct? Moreover, I am unable to ping the IP from inside the container.
Can anyone please help me.
apiVersion: v1
kind: Endpoints
metadata:
name: sql-server
subsets:
- addresses:
- ip: 1.1.1.1
ports:
- port: 1433
apiVersion: v1
kind: Service
metadata:
name: sql-server
spec:
type: ClusterIP
ports:
- port: 1433
targetPort: 1433
I reproduced a similar scenario in my minikube system and this solution works as described. I will drive you through the setup and how to troubleshoot this issue.
I have a linux server (hostname http-server) and I installed a http server (apache2) in on it that's serving a hello world message:
user@http-server:~$ netstat -tan | grep ::80
tcp6 0 0 :::80 :::* LISTEN
user@minikube-server:~$ curl 10.128.15.209
Hello World!
Now that we confirmed that my service is accessible from the machine where I have minikube installed, lets connect to minikube VM and check if I can access this http service:
user@minikube-server:~$ minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ curl 10.128.15.209
Hello World!
Great! This is looking good. If you can't access your service here, you have to check your network, something is preventing your minikube server from communicating with your service.
Now let's exit from this minikube ssh and create our endpoint:
My endpoint manifest is looking like this:
apiVersion: v1
kind: Endpoints
metadata:
name: http-server
subsets:
- addresses:
- ip: 10.128.15.209
ports:
- port: 80
user@minikube-server:~$ kubectl apply -f http-server-endpoint.yaml
endpoints/http-server configured
Let's create our service:
apiVersion: v1
kind: Service
metadata:
name: http-server
spec:
ports:
- port: 80
targetPort: 80
user@minikube-server:~$ kubectl apply -f http-server-service.yaml
service/http-server created
Checking if our service exists and save it's clusterIP for letter usage:
user@minikube-server:~$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
http-server ClusterIP 10.96.228.220 <none> 80/TCP 30m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10d
Now it's time to verify if we can access our service from a pod:
kubectl run ubuntu -it --rm=true --restart=Never --image=ubuntu bash
This command will create and open a bash session inside a ubuntu pod.
In my case I'll install curl to be able to check if I can access my http server. You may need install mysql:
root@ubuntu:/# apt update; apt install -y curl
Checking connectivity with my service using clusterIP:
root@ubuntu:/# curl 10.128.15.209:80
Hello World!
And finally using the service name (DNS):
root@ubuntu:/# curl http-server
Hello World!
Please run into all these steps and let me know if you have trouble on any and where.