<p>This is a Java Spring boot REST API application, using an index.html to present the UI web page to user.
When the index.html is displayed, it would trigger the logic from the Javascript/jQuery to make a REST api call(coded as below) to the backend service in the Java controller class to get 2 random generated numbers:</p>

<pre><code>$.ajax({
    url: "http://localhost:8080/multiplications/random"
</code></pre>

<p>The program is working fine when run it as a Spring Boot app in Eclipse!</p>

<p>However, it's not working after I used the .jar file to build a Docker image file then deployed it using Kubernetes/minikube(I'm new to Docker/Kubernetes).</p>

<p>here's the dockfile to build the image file using the .jar:</p>

<pre><code>FROM openjdk:latest

ADD target/social-multiplication-v3-0.3.0-SNAPSHOT.jar app.jar

ENTRYPOINT ["java","-jar","app.jar"]

EXPOSE 8080
</code></pre>

<p>Here's the deployment.yaml file:</p>

<pre><code>---
kind: Service
apiVersion: v1
metadata:
  name: multiplicationservice
spec:
  selector: 
      app: multiplication
  ports:
     - protocol: "TCP"
       port:  80
       targetPort:  8080
       nodePort:  30001
  type: LoadBalancer

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mdeploy
spec:
  replicas: 1
  selector: 
    matchLabels:
      app: multiplication
  template:
    metadata:
      labels:
        app: multiplication
    spec:
      containers:
      - name: multiplication
        image: huxianjun/multiplication
        ports:
        - containerPort: 80
</code></pre>

<p>and the IP address of the host where the application being deployed in Kubernetes:</p>

<pre><code>$ minikube ip
192.168.99.101
</code></pre>

<p>At the end, I can get to the index.html page from browser by folllowing URL:</p>

<pre><code>http://192.168.99.101:30001/
</code></pre>

<p>The page is being displayed as expected - What NOT working is, the following REST api call didn't occur thus the 2 numbers not returned from the call and displayed on the page:</p>

<pre><code>$.ajax({
    url: "http://localhost:8080/multiplications/random"
</code></pre>

<p>My guess is, is it caused by the 'localhost' &amp; the port'8080' not aligned with those port# defined in the deployment.yaml file? or even something conflict to the 'EXPOSE 8080' in the docfile?</p>

Roy Hu
<p>In your case, you are calling the <code>$.ajax</code> command from your browser which is in your host machine, hence, those API calls will be sent from your local machine but not within your docker container.</p>

<p>To solve the problem, you can update the URL to be using <code>http://192.168.99.101:30001/</code> like this</p>

<pre><code>$.ajax({
    url: "http://192.168.99.101:30001/multiplications/random"
</code></pre>
