4

I'm deploying a spring boot app in minikube that connects to a database running on the host. Where do I find the IP address that the app can use to get back to the host? For docker I can use ifconfig and get the IP address from the docker0 entry. ifconfig shows another device with IP address 172.18.0.1. Would that be how my app would get back to the host?

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165

2 Answers2

5

I think I understood you correctly and this is what you are asking for.

Minikube is started as a VM on your machine. You need to know the IP which Minikube starts with. This can be done with minikube status or minikube ip, output might look like:

$ minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.1

This will only provide you the IP address of Minikube not your application. In order to connect to your app from outside the Minikube you need to expose it as a Service.

Example of a Service might look like this:

apiVersion: v1  
kind: Service  
metadata:  
  name: webapp  
spec:  
  type: NodePort  
  ports:  
    - nodePort: 31317  
      port: 8080  
      protocol: TCP  
      targetPort: 8080  
  selector:  
    app: webapp

You can see results:

$ kubectl get services -o wide  
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE       SELECTOR  
postgres   ClusterIP   10.0.0.140   <none>        5432/TCP         32m       app=postgres  
webapp     NodePort    10.0.0.235   <none>        8080:31317/TCP   2s        app=webapp

You will be able to connect to the webapp from inside the Cluster using 10.0.0.235:8080 of from outside the Cluster using Minikube IP and port 31317.

I also recommend going through Hello Minikube tutorial.

Crou
  • 10,232
  • 2
  • 26
  • 31
-2

It was the 172.18.0.1 IP address. I passed it to the Spring app running in minikube with a configmap like this:

kubectl create configmap springdatasourceurl --from-literal=SPRING_DATASOURCE_URL=jdbc:postgresql://172.18.0.1:5432/bookservice

The app also needed SPRING_DATASOURCE_DRIVER_CLASS_NAME to be set in a configmap and that credentials SPRING_DATASOURCE_PASSWORD and SPRING_DATASOURCE_USERNAME be set as secrets.

More information on configmap and secret are here.

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165