<p>I am newbie to Kubernetes and had a long time configuring my application to be hosted on Kubernetes cluster hosted on AWS EKS.</p>

<p><strong>Status-quo</strong>: I am pretty sure that the service of type <code>LoadBalancer</code> is up and running. It has its pod and all the stuff running. The application is simple Java application with input. You can try accessing it by pulling an image from Docker Hub via:</p>

<pre><code>docker run -i ardulat/mckinsey
</code></pre>

<p><strong>Question</strong>: how can I run the Java application (not Spring, not REST) that is being hosted on Kubernetes cluster?</p>

<p><strong>Already tried</strong>:</p>

<ul>
<li><code>curl -v &lt;EXTERNAL-IP&gt;:&lt;PORT&gt;</code> that outputs:</li>
</ul>

<pre><code>*   Trying 3.134.148.191...
* TCP_NODELAY set
* Connected to a8154210d09da11ea9c3806983848f2f-1085657314.us-east-2.elb.amazonaws.com (3.134.148.191) port 8080 (#0)
&gt; GET / HTTP/1.1
&gt; Host: a8154210d09da11ea9c3806983848f2f-1085657314.us-east-2.elb.amazonaws.com:8080
&gt; User-Agent: curl/7.63.0
&gt; Accept: */*
&gt;
* Empty reply from server
* Connection #0 to host a8154210d09da11ea9c3806983848f2f-1085657314.us-east-2.elb.amazonaws.com left intact
curl: (52) Empty reply from server
</code></pre>

<ul>
<li><code>nc -v &lt;EXTERNAL-IP&gt; &lt;PORT&gt;</code> that outputs:</li>
</ul>

<pre><code>found 0 associations
found 1 connections:
     1: flags=82&lt;CONNECTED,PREFERRED&gt;
    outif en0
    src 172.20.22.42 port 63865
    dst 3.13.128.24 port 8080
    rank info not available
    TCP aux info available

Connection to a8154210d09da11ea9c3806983848f2f-1085657314.us-east-2.elb.amazonaws.com port 8080 [tcp/http-alt] succeeded!
</code></pre>

<p>Therefore, I assume that connection works and the service is up and running except I am trying to connect to the Java (.jar) application in the wrong way. Do you have any suggestions?</p>

Anuar Maratkhan
<p>You should change your <code>dockerfile</code> and change <strong>CMD</strong> to <strong>ENTRYPOINT</strong> which is nicely explained <a href="https://goinbigdata.com/docker-run-vs-cmd-vs-entrypoint/" rel="nofollow noreferrer">here</a>.
I would also recommend reading <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/" rel="nofollow noreferrer">Define a Command and Arguments for a Container</a>.</p>

<blockquote>
  <ul>
  <li>CMD sets default command and/or parameters, which can be overwritten from command line when docker container runs.</li>
  <li>ENTRYPOINT configures a container that will run as an executable.</li>
  </ul>
</blockquote>

<p>Your <code>dockerfile</code> might look like this:</p>

<pre><code>FROM java:8
WORKDIR /
ADD Anuar.jar Anuar.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","Anuar.jar"]
</code></pre>

<p>Your service might look like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: javaservice
  labels:
    app: javaservice
spec:
  type: LoadBalancer
  selector:
    app: javaservice
  ports:
  - protocol: TCP
    port: 8080
    name: http
</code></pre>

<p>Also it's important which LoadBalancer you want to use as on AWS there is Classic Load Balancer which is default and <a href="https://kubernetes.io/docs/concepts/services-networking/service/#aws-nlb-support" rel="nofollow noreferrer">Network Load Balancer</a>. You can read more about it on <a href="https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer" rel="nofollow noreferrer">Internal load balancer</a> and check the AWS documentation for <a href="https://docs.aws.amazon.com/eks/latest/userguide/load-balancing.html" rel="nofollow noreferrer">Load Balancing</a>.</p>

<blockquote>
  <p>Amazon EKS supports the Network Load Balancer and the Classic Load Balancer through the Kubernetes service of type  <code>LoadBalancer</code>. The configuration of your load balancer is controlled by annotations that are added to the manifest for your service.</p>
  
  <p>By default, Classic Load Balancers are used for  <code>LoadBalancer</code>  type services. To use the Network Load Balancer instead, apply the following annotation to your service:</p>
  
  <p><code>service.beta.kubernetes.io/aws-load-balancer-type: nlb</code></p>
  
  <p>For more information about using Network Load Balancer with Kubernetes, see  <a href="https://kubernetes.io/docs/concepts/services-networking/service/#aws-nlb-support" rel="nofollow noreferrer">Network Load Balancer support on AWS</a>  in the Kubernetes documentation.</p>
  
  <p>By default, services of type  <code>LoadBalancer</code>  create public-facing load balancers. To use an internal load balancer, apply the following annotation to your service:</p>
  
  <p><code>service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0</code></p>
  
  <p>For internal load balancers, your Amazon EKS cluster must be configured to use at least one private subnet in your VPC. Kubernetes examines the route table for your subnets to identify whether they are public or private. Public subnets have a route directly to the internet using an internet gateway, but private subnets do not.</p>
</blockquote>
