我有一个带有uwsgi和gevent的flask应用。
这是我的app.ini
如何在kubernetes上编写readinessProbe和livenessProbe来检查烧瓶应用程序?
[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
答案 0 :(得分:2)
我认为您真正要问的是“如何对uWSGI应用程序进行健康检查”。有一些示例工具可以执行此操作。特别是:
uwsgi-tools
项目似乎在https://github.com/andreif/uwsgi-tools/issues/2#issuecomment-345195583上有最完整的示例。在Kubernetes Pod规范上下文中,结果可能看起来像这样:
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
这还将假定您的应用程序对/health
作为运行状况终结点做出了响应。
答案 1 :(得分:0)
您可以将uWSGI
配置为同时在uwsgi-socket
侧投放http-socket
,并且仅将uwsgi-socket
暴露给k8s service
。
在这种情况下,您的uwsgi.ini
类似于:
[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
假设您的应用中有/health
个终结点,则k8s manifest
可能类似于:
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
在这种情况下,您的服务将通过socket = /tmp/uwsgi.sock
作为上游k8s service
的位置而到达,而k8s healthcheck
服务可以到达http-socket: 5050
的容器。