<p>I have a local Docker setup consisting of four containers: a flask web app, MySQL, Redis, and an RQ worker.</p>

<p>The setup is essentially the same as Miguel Grinberg's Flask Mega-Tutorial. Here are links for his <a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs" rel="nofollow noreferrer">tutorial</a> and his <a href="https://github.com/miguelgrinberg/microblog/tree/v0.22" rel="nofollow noreferrer">code</a>.</p>

<p>The only difference in my case is that I've replaced his export blog post function, which runs on the rq-worker, with another that is incredibly computationally intensive and long running (30 minutes).</p>

<p><strong>What is the best way for me to deploy this application for production?</strong> </p>

<p>I only expect it to be accessed by a one or two people at a time and for them to visit only once or twice a week.</p>

<p>I've been looking into Kubernetes examples but I'm having difficulty translating them to my setup and figuring out how to deploy to GCP. I'm open to other deployment options.</p>

<p>Here are the docker run commands from the tutorial:</p>

<p><code>docker run --name redis -d -p 6379:6379 redis:3-alpine</code></p>

<pre><code>docker run --name mysql -d -e MYSQL_RANDOM_ROOT_PASSWORD=yes \
    -e MYSQL_DATABASE=flaskapp -e MYSQL_USER=flaskapp \
    -e MYSQL_PASSWORD=mysqlpassword \
    mysql/mysql-server:5.7
</code></pre>

<pre><code>docker run --name rq-worker -d --rm -e SECRET_KEY=my-secret-key \
    -e MAIL_SERVER=smtp.googlemail.com -e MAIL_PORT=587 -e MAIL_USE_TLS=true \
    -e MAIL_USERNAME=example@gmail.com -e MAIL_PASSWORD=mysqlpassword \
    --link mysql:dbserver --link redis:redis-server \
    -e DATABASE_URL=mysql+pymysql://flaskapp:mypassword@dbserver/flaskapp \
    -e REDIS_URL=redis://redis-server:6379/0 \
    --entrypoint venv/bin/rq \
    flaskapp:latest worker -u redis://redis-server:6379/0 dyson-tasks
</code></pre>

<pre><code>docker run --name flaskapp -d -p 8000:5000 --rm -e SECRET_KEY=my_secret_key \
    -e MAIL_SERVER=smtp.googlemail.com -e MAIL_PORT=587 -e MAIL_USE_TLS=true \
    -e MAIL_USERNAME=example@gmail.com -e MAIL_PASSWORD=mypassword \
    --link mysql:dbserver --link redis:redis-server  \
    -e DATABASE_URL=mysql+pymysql://flaskapp:mysqlpassword@dbserver/flaskapp \
    -e REDIS_URL=redis://redis-server:6379/0 \
    flaskapp:latest 
</code></pre>

Scott Guthart
<p>I made a getting started project for a rq on GCP/GKE that should roughly fit your needs.
<a href="https://github.com/crispyDyne/GKE-rq" rel="nofollow noreferrer">https://github.com/crispyDyne/GKE-rq</a></p>
<p>It consists of three workloads:</p>
<ul>
<li>Leader: A flask app that receives external traffic and enqueues jobs.</li>
<li>Worker: Starts an rq worker.</li>
<li>Dashboard: Serves a dashboard for monitoring the queue.</li>
</ul>
<p>A google memory store instance is used for the redis server. If you are looking to do this on the cheap, this should be swapped out for a container running redis (but I was lazy).</p>
<p>How to create memory store redis instance: <a href="https://cloud.google.com/memorystore/docs/redis/quickstart-gcloud" rel="nofollow noreferrer">https://cloud.google.com/memorystore/docs/redis/quickstart-gcloud</a></p>
<p>Also, I use a node port to expose the Leader app, instead of a load balancer. Load balancers are surprisingly expensive. For small/cheap projects, the node port should work fine.</p>
<hr />
<p>There were a few non-obvious steps for a novice (like me) to get everything talking.</p>
<p><strong>How to connect the &quot;Leader&quot; to the redis queue.</strong></p>
<p>Get the redis IP from the GCP console or <code>gcloud redis instances describe ...</code>.</p>
<p>In your flask app:</p>
<pre><code>redis_conn = Redis(host={redisIP}, port=6379, db=0)
q = Queue('rq-server', connection=redis_conn)
</code></pre>
<p><strong>How to connect the &quot;Folower&quot; to the redis queue.</strong></p>
<p>DockerFile:</p>
<pre><code>FROM python:3
COPY . /app
WORKDIR /app
RUN pip install --no-cache-dir -r requirements.txt
ENV PORT 6379
CMD [ &quot;rq&quot;, &quot;worker&quot;,&quot;--url&quot;, &quot;redis://{redisIP}:6379&quot;, &quot;rq-server&quot; ]
</code></pre>
<p><strong>How to connect the &quot;Dashboard&quot; to the redis queue.</strong></p>
<p>DockerFile:</p>
<pre><code>FROM python:3
COPY . /app
WORKDIR /app
RUN pip install --no-cache-dir -r requirements.txt
ENV PORT 9181
CMD [ &quot;rq-dashboard&quot;,&quot;-u&quot;, &quot;redis://{redisIP}:6379&quot;]
</code></pre>
<p><strong>How to expose the Leader  through a node port</strong> (or similarly the Dashboard).</p>
<p>Note the target port. Should be 8080 for a flask app, or 9181 for the rq-dashboard.</p>
<pre><code>kubectl expose deployment rq-leader --name rq-leader-service /
 --type NodePort --port 80 --target-port 8080
</code></pre>
<p>Then open the {NodePort}. Get the node port on the GCP console or with <code>kubectl get services ...</code>.</p>
<pre><code>gcloud compute firewall-rules create node-port-leader--allow tcp:{NodePort}

</code></pre>
