How to configure a Flask ws in Kubernetes with SSL?

6/27/2019

I have a containerized Flash application (a simple webservice exposed in the internet) with SSL enabled by gunicorn through:

CMD ["gunicorn", "--certfile", "/var/tmp/fullchain.pem", "--keyfile", "/var/tmp/key.pem", "__init__:create_app()", "-b", ":8080"]

I have a bot that renews Let's Encrypt certificates in this path every 3 months.

Now I am creating a Kubernetes cluster to put this application an orchestrate the replicas.

In a related question I've seen some ingress controllers provide this certificate creation/renew functionality so I would not need to map to .pem files anymore. There is also cert-manager that does that.

Now I don't know if I need gunicorn or what is the easyest and recommended way to configuring that to run the application. I am also in the process of chosing an ingress controller for my cluster.

-- staticdev
flask
gunicorn
kubernetes
ssl

2 Answers

6/28/2019

Now I don't know if I need gunicorn.

Gunicorn is like java Tomcat, and it can also improve performance for python web server, so using Gunicorn is also recommend without SSL.

If you have other service in same cluster want to talk to your Flask server, and you want to protect that connection, you should config Gunicorn with SSL. If not, I think using an ingress controller with certificate manager is convenient.

I am also in the process of chosing an ingress controller for my cluster.

Well, I think cert-manager offical doc can help you, it deploy cert-manager with Nginx ingress controller.

-- menya
Source: StackOverflow

6/28/2019

Theoretically you don't need to resign from your current setup: Flask app exposed on HTTPS.
For instance the NGINX ingress controller can pass (encrypted) TLS packets directly to an upstream server (in your case Gunicorn) using SSL Passthrough feature.

But definitely it would be better to do it in a recommended Kubernetes way, with TLS enabled for Ingress (where cert-manager add-on can help you in obtaining certificates from sources like Let's Encrypt)

-- Nepomucen
Source: StackOverflow