Unable to access my application on minikube

10/3/2019

I am new on kubernetes and I tried to run small app using kubernetes. I created docker image and used minikube to run it. So application is very simple, it just prints hello-world.

@RestController
@RequestMapping(value = "helloworld")
public class MyController {

    @GetMapping
    public HelloWord helloWord(){

        return new HelloWord("Hello Word");
    }
}

My dockerfile:

FROM adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim
VOLUME /tmp
ARG JAR_FILE=target/myapp-1.0.0.jar
COPY ${JAR_FILE} myapp-1.0.0.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-jar","/myapp-1.0.0.jar"]

deployment.yaml

apiVersion: v1
kind: Service
metadata:
  name: myhelloworldservice
spec:
  selector:
    app: my-hello-world-app
  ports:
    - protocol: "TCP"
      port: 8080
      targetPort: 80
      nodePort: 30003
  type: LoadBalancer


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-hello-world
spec:
  selector:
    matchLabels:
      app: my-hello-world-app
  replicas: 5
  template:
    metadata:
      labels:
        app: my-hello-world-app
    spec:
      containers:
        - name: hello-world
          image: myname/myhelloimage
          ports:
            - containerPort: 80

I run the command :

kubectl create -f deployment.yaml

and the output is :

service/myhelloworldservice created

created deployment.apps/my-hello-world

I run minikube ip command to get ip and then used that ip adress to access my app by using port 30003, but not able to access my app.

I used :

http://xxx.xx.xx.xxx:30003/helloworld

What is the problem why I cannot access to my app? I am getting This site can’t be reached. Refused to connect error.

-- user1474111
cloud
containers
kubernetes
minikube

3 Answers

10/5/2019

You can port forward from your minikube to your localhost using kubectl port-forward <<created_container_name>> 80 Now you should be able to access your app through a browser with localhost:80/helloworld

-- javin
Source: StackOverflow

10/5/2019

Looking at the code, it appears that it is a Spring-based service. It is unlikely that the service listens on port 80 - the default for Spring is 8080. So, assuming the actual port is 8080, change:

  • targetPort: 80 to targetPort: 8080 in the Service definition.
  • type: LoadBalancer over to type: NodePort in the Service definition.
  • containerPort: 80 to containerPort: 8080 in the Deployment definition.
-- apisim
Source: StackOverflow

10/3/2019

Your service is of type LoadBalancer, which are particular to access. With Minikube you can access them using:

minikube tunnel

For more information see https://minikube.sigs.k8s.io/docs/tasks/loadbalancer/

-- Glenn
Source: StackOverflow