Minikube VM hyperkit: Spring Boot: connect to local machine

12/18/2018

I have a minikube cluster running on Mac OSX and a simple Spring Boot REST api that connects to Redis and Mongo DB, which I have installed and running locally.

I wish not to run Redis / MongoDb in a Docker container.
I will probably run them remotely in the cloud, therefore I would probably just connect to an external IP address.

What I don't understand is what IP address I should use to connect to my localhost machine.
I start up my Minikube with VM hyperkit.

Edit: I also tried to start using virtualbox:

minikube start --vm-driver=virtualbox

In my spring boot application, I've configured:

spring.data.mongodb.host = 10.0.2.2 
spring.redis.host = 10.0.2.2 

But still, I get connection errors:

enter image description here

enter image description here

This works when I run the application locally on my host machine.

For the sake of completeness, this is my yaml file:

---
apiVersion: v1
kind: Service
metadata:
  name: posts-api
  labels:
    app: posts-api
    env: dev
spec:
  type: NodePort
  selector:
    app: posts-api
  ports:
  - protocol: TCP
    port: 8083
    name: http

---
apiVersion: v1
kind: ReplicationController
metadata:
  name: posts-api
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: posts-api
    spec:
      containers:
      - name: posts-api
        image: kimgysen/posts-api:latest
        ports:
        - containerPort: 8083
        livenessProbe:
          httpGet:
            path: /health
            port: 8083
          initialDelaySeconds: 120
          timeoutSeconds: 3
-- Trace
kubernetes
minikube
spring-boot

1 Answer

12/19/2018

I'll give you the answer I gave to someone with the same problem (different tech):

Kubernetes pod unable to connect to rabbit mq instance running locally

Replace the IP and port number, and the Service and Endpoints names as appropriate.

-- apisim
Source: StackOverflow