<p>Is there any standard to deploy flask app with gunicorn and nginx on kubernetes cluster
because I am trying to it by on dockerfile like below:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>FROM nginx:latest as base-image
RUN apt update
RUN apt -y install python3 python3-pip
RUN apt -y install build-essential 

RUN mkdir /app
WORKDIR /app
COPY src src/
COPY src/.nginx/config /etc/nginx/conf.d/default.conf
COPY requirements.txt ./
RUN pip3 install -r requirements.txt

RUN pip3 install -e ./src
RUN pwd
RUN ls -l /app/src

# RUN pytest

EXPOSE 80

WORKDIR /app/src
CMD ["nginx", "-g", "daemon off;"]
ENTRYPOINT ["gunicorn" , "--bind","0.0.0.0:8000", "wsgi:app"]</code></pre>
</div>
</div>
</p>
<p>Is the solution is to run two containers for each of gunicorn and nginx inside one pod of kubernetes?</p>

<blockquote>
<p>Is the solution is to run two containers for each of gunicorn and nginx inside one pod of kubernetes?</p>
</blockquote>
<p>Yes. In Kubernetes or when simply running Docker on your local machine, it is always better to compose multiple containers rather than trying to stuff everything into a single container.</p>
<p>This part of your your Dockerfile:</p>
<pre><code>CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]
ENTRYPOINT [&quot;gunicorn&quot; , &quot;--bind&quot;,&quot;0.0.0.0:8000&quot;, &quot;wsgi:app&quot;]
</code></pre>
<p>Isn't doing what you seem to expect. These two directives operate in concert:</p>
<ul>
<li>If defined, <code>ENTRYPOINT</code> is the command run by the container when it starts up.</li>
<li>The value of <code>CMD</code> is provided as an argument to the <code>ENTRYPOINT</code> script.</li>
</ul>
<p>You can read more about <code>ENTRYPOINT</code> in the <a href="https://docs.docker.com/engine/reference/builder/#entrypoint" rel="nofollow noreferrer">official documentation</a>.</p>
<p>A better design would be to use the official Python image for your Python app:</p>
<pre><code>FROM python:3.10

WORKDIR /app

COPY src src/
COPY requirements.txt ./
RUN pip3 install -r requirements.txt
RUN pip3 install -e ./src

WORKDIR /app/src
CMD [&quot;gunicorn&quot; , &quot;--bind&quot;,&quot;0.0.0.0:8000&quot;, &quot;wsgi:app&quot;]
</code></pre>
<p>And then use the official <a href="https://hub.docker.com/_/nginx" rel="nofollow noreferrer">nginx image</a> to run the nginx service.</p>
<hr />
<p>An example deployment that uses two containers, one for your Python app and one for Nginx, might look like:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: flask-example
  name: flask-example
spec:
  selector:
    matchLabels:
      app: flask-example
  template:
    metadata:
      labels:
        app: flask-example
    spec:
      containers:
      - image: quay.io/larsks/example:flaskapp
        name: app
      - image: docker.io/nginx:mainline
        name: nginx
        ports:
        - containerPort: 80
          name: http
        volumeMounts:
        - mountPath: /etc/nginx/conf.d
          name: nginx-config
      volumes:
      - configMap:
          name: nginx-config-c65tttk45k
        name: nginx-config
</code></pre>
<p>In the above deployment, we're mounting the configuration for nginx from a ConfigMap.</p>
<p>You can find a complete deployable example of the above <a href="https://github.com/larsks/so-example-73785638/" rel="nofollow noreferrer">here</a>.</p>
