title: Exposing Docker container port in Kubernetes config
body: <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>