kubernetes Minikube : Node port service not accessible from outside

4/3/2020

I am trying to deploy simple spring boot REST service on minikube (Windows-10). Below are my configuration

Docker file

FROM openjdk:8-jdk-alpine
ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/myservice/minikube-spring-boot-demo-0.0.1-SNAPSHOT.jar"]
ADD target/minikube-spring-boot-demo-0.0.1-SNAPSHOT.jar  /usr/share/myservice/lib
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/myservice/minikube-spring-boot-demo-0.0.1-SNAPSHOT.jar
EXPOSE 8080

docker image is running fine and i am able to run the app.

docker run -p 8080:8080 minikube-spring-boot-demo:0.0.1-SNAPSHO

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: minikube-spring-boot-demo
spec:
  selector:
    matchLabels:
      app: minikube-spring-boot-demo
      tier: backend
  replicas: 3
  template:
    metadata:
      labels:
        app: minikube-spring-boot-demo
        tier: backend
    spec:
      containers:
        - name: demo-backend
          image: nirajsonawane/minikube-spring-boot-demo:0.0.1-SNAPSHOT
          imagePullPolicy: Always
          ports:
            - containerPort: 8080

Service

apiVersion: v1
kind: Service
metadata:
  name: minikube-spring-boot-demo-service
spec:
  selector:
    app: minikube-spring-boot-demo
    tier: backend
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30008
  type: NodePort

kubectl get all status enter image description here

kubectl cluster-info enter image description here

minikube logs enter image description here

Service Details enter image description here

i am not able to access the rest endpoint using service-ip:Nodeport/Uri
http://127.0.0.1:30008/hello

http://172.17.0.2:30008/hello

Anything i am missing here? any inputs will be useful.

output of netstat -a

enter image description here

-- Niraj Sonawane
kubernetes
minikube
spring-boot

2 Answers

4/3/2020

You can get you cluster ip using below command

kubectl get nodes -o wide

then run below to get nodeport

kubectl get svc -o wide -n <namespace>

get the port of your NodePort Svc

then your application will be running on http://:port(svc Nodeport )

In your case it might be running on http://127.0.0.1:30008/hello

-- Dhiraj Surve
Source: StackOverflow

4/4/2020

minikube is running in a virtual machine. Services can't be accessed through either localhost or 127.0.0.1 out of the machine.

Try to run minikube service minikube-spring-boot-demo-service. It will show service details and open the service in the browser.

-- kitt
Source: StackOverflow