How to check uwsgi with gevent at socket file in k8s readinessProbe and livenessProbe

7/20/2019

I have a flask app with uwsgi and gevent.
Here is my app.ini How could I write readinessProbe and livenessProbe on kubernetes to check to flask app?

[uwsgi]
socket = /tmp/uwsgi.sock
chdir = /usr/src/app/
chmod-socket = 666
module = flasky
callable = app
master = false
processes = 1
vacuum = true
die-on-term = true
gevent = 1000
listen = 1024
-- Rukeith
gevent
kubernetes
uwsgi

2 Answers

9/19/2019

You can configure uWSGI to serve both uwsgi-socket along side http-socket, and only expose the uwsgi-socket to the k8s service.

In this case your uwsgi.ini would looks something like:

[uwsgi]
socket = /tmp/uwsgi.sock
chdir = /usr/src/app/
chmod-socket = 666
module = flasky
callable = app
master = false
processes = 1
vacuum = true
die-on-term = true
gevent = 1000
listen = 1024

http-socket = 0.0.0.0:5050

And assuming you have /health endpoint in your app, your k8s manifest can be something like:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: myapp
    image: myimage
    livenessProbe:
      httpGet:
        path: /health
        port: 5050
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 5
      periodSeconds: 5

In this case, your service will be reachable sitting as the upstream at socket = /tmp/uwsgi.sock via your k8s service and the k8s healthcheck service can reach your container at http-socket: 5050.

-- ShahNewazKhan
Source: StackOverflow

7/21/2019

I think what you are really asking is "How to health check a uWSGI application". There are some example tools to do this. Particularly:

The uwsgi-tools project seems to have the most complete example at https://github.com/andreif/uwsgi-tools/issues/2#issuecomment-345195583. In a Kubernetes Pod spec context this might end up looking like:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: myapp
    image: myimage
    livenessProbe:
      exec:
        command:
        - uwsgi_curl
        - -H
        - Host:host.name
        - /path/to/unix/socket
        - /health
      initialDelaySeconds: 5
      periodSeconds: 5

This would also assume your application responded to /health as a health endpoint.

-- Andy Shinn
Source: StackOverflow