I want to run this Spring Boot application inside Minikube so that I can reach port 8080
in my browser (once the application is running).
To do so, I do following steps.
mvn spring-boot:build-image
.minikube start
.kubectl create deployment example-1-engine-1 --image=example-1-engine-1
.kubectl expose deployment example-1-engine-1 --type=NodePort --port=8080
and kubectl port-forward service/example-1-engine-1 8080:8080
.minikube service example-1-engine-1
.Following output appears:
However, the browser cannot open the web application on port 8080 (browser cannot connect to the application at http://127.0.0.1:50947/).
What am I doing wrong and how can I make sure that the application in question runs inside Minikube and I can access the web application at port 8080?
Update 1: Here is the output of kubectl get pods
:
C:\Users\XXXXXXX>kubectl get pods
NAME READY STATUS RESTARTS AGE
example-1-engine-1-d9fc48785-zdvkf 0/1 ImagePullBackOff 0 2d18h
hello-minikube-6ddfcc9757-wj6c2 1/1 Running 1 5d
Update 2: I tried to enter eval $(minikube -p minikube docker-env)
. For this purpose, I first opened the shell of Minikube container in Docker.
In the window that appeared thereafter, I entered eval $(minikube -p minikube docker-env)
and got the response minikube: not found
.
In my opinion, there are two possible issues with your case.
You want to run locally built Docker image in Kubernetes, but it doesn't work out-of-the-box. Generally, you have two options:
1) Use docker image push
command to share your image to the Docker Hub registry or to a self-hosted one as described in the Docker documentation.
2) Use eval $(minikube docker-env)
command to point your terminal to use the docker daemon inside minikube as described in the minikube documentation.
As I can see, your image has specific tag 1.0-SNAPSHOT
:
$ docker images
REPOSITORY TAG
example-1-engine-1 1.0-SNAPSHOT
You need to specify this tag in your kubectl create deployment
command:
$ kubectl create deployment example-1-engine-1 --image=example-1-engine-1:1.0-SNAPSHOT
I've deployed your Spring Boot application, to show that it works as expected for me.
First, to point my terminal to use the docker daemon inside minikube I ran:
$ eval $(minikube -p minikube docker-env)
Then I created Docker image and deployed example-1-engine-1
app:
$ mvn spring-boot:build-image
...
[INFO] Successfully built image 'docker.io/library/example-1-engine-1:1.0-SNAPSHOT'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
$ kubectl create deployment example-1-engine-1 --image=example-1-engine-1:1.0-SNAPSHOT
deployment.apps/example-1-engine-1 created
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
example-1-engine-1-c98f8c569-xq2cv 1/1 Running 0 13s
Finally, I exposed the example-1-engine-1
Deployment
as in your example:
$ kubectl expose deployment example-1-engine-1 --type=NodePort --port=8080
service/example-1-engine-1 exposed
$ kubectl port-forward service/example-1-engine-1 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
$ minikube service example-1-engine-1
|-----------|--------------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------------|-------------|---------------------------|
| default | example-1-engine-1 | 8080 | http://192.168.49.2:32766 |
|-----------|--------------------|-------------|---------------------------|
Opening service default/example-1-engine-1 in default browser...
In the open browser tab, I saw:
Additionally, I saw the same page at http://127.0.0.1:8080
.
Unfortunately, I don't have Windows machine (as in your example) and I used Linux instead, so I wasn't able to exactly reproduce your issue.