<p>I'm trying to deploy a Flask python API to Kubernetes (EKS). I've got the Dockerfile setup, but with some weird things going on.</p>
<p><code>Dockerfile</code>:</p>
<pre><code>FROM python:3.8
 
WORKDIR /app
COPY . /app
 
RUN pip3 install -r requirements.txt
 
EXPOSE 43594

ENTRYPOINT [&quot;python3&quot;]
CMD [&quot;app.py&quot;]
</code></pre>
<p>I build the image running <code>docker build -t store-api .</code>.</p>
<p>When I try running the container and hitting an endpoint, I get <code>socker hung up</code>. However, if I run the image doing</p>
<pre class="lang-sh prettyprint-override"><code>docker run -d -p 43594:43594 store-api
</code></pre>
<p>I can successfully hit the endpoint with a response.</p>
<p><strong>My hunch is the port mapping.</strong></p>
<p>Now having said all that, running the image in a Kubernetes pod, I cannot get anything back from the endpoint and get <code>socket hung up</code>.</p>
<p>My question is, how do I explicitly add port mapping to my Kubernetes deployment/service?</p>
<p>Part of the <code>Deployment.yaml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>    spec:
      containers:
        - image: store-api
          name: store-api
          ports:
            - containerPort: 43594
          resources: {}
          volumeMounts:
            - mountPath: /usr/local/bin/wait-for-it.sh
              name: store-api-claim0
          imagePullPolicy: Always
</code></pre>
<p><code>Service.yaml</code>:</p>
<pre><code>spec:
  type: LoadBalancer
  ports:
    - port: 43594
      protocol: TCP
      targetPort: 43594
  selector:
    app: store-api
status:
  loadBalancer: {}
</code></pre>
<p>If I port forward using <code>kubectl port-forward deployment/store-api 43594:43594</code> and post the request to <code>localhost:43594/</code> it works fine.</p>

Taylan Selvi
<p><em>This is a community wiki answer posted for better visibility. Feel free to expand it.</em></p>
<p><strong>Problem</strong></p>
<p>Output for <code>kubectl describe service &lt;name_of_the_service&gt;</code> command contains <code>Endpoints: &lt;none&gt;</code></p>
<p><strong>Some theory</strong></p>
<p>From Kubernetes Glossary:</p>
<p><a href="https://kubernetes.io/docs/reference/glossary/?all=true#term-service" rel="nofollow noreferrer">Service</a></p>
<blockquote>
<p>An abstract way to expose an application running on a set of Pods as a
network service. The set of Pods targeted by a Service is
(usually) determined by a selector. If more Pods are added or removed,
the set of Pods matching the selector will change. The Service makes
sure that network traffic can be directed to the current set of Pods
for the workload.</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/reference/glossary/?all=true#term-endpoints" rel="nofollow noreferrer">Endpoints</a></p>
<blockquote>
<p>Endpoints track the IP addresses of Pods with matching selectors.</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/reference/glossary/?all=true#term-selector" rel="nofollow noreferrer">Selector</a>:</p>
<p>Allows users to filter a list of resources based on labels. Selectors are applied when querying lists of resources to filter them by labels.</p>
<p><strong>Solution</strong></p>
<p>Labels in <code>spec.template.metadata.labels</code> of the Deployment should be the same as in <code>spec.selector</code> from the Service.</p>
<p>Additional information related to such issue can be found at <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/#does-the-service-have-any-endpoints" rel="nofollow noreferrer">Kubernetes site</a>:</p>
<blockquote>
<p>If the ENDPOINTS column is &lt;none&gt;, you should check that the
spec.selector field of your Service actually selects for
metadata.labels values on your Pods.</p>
</blockquote>
