如何优雅地停止 Laravel 队列工作者,作为 docker 映像运行?



我们正在 Kubernetes 上部署一个 Laravel 应用程序。只是应用程序不是问题,但队列工作人员是。我们从多个来源了解到,建议将队列工作程序作为单独的部署运行。因此,在 kubeconfig 部分下方,该部分将队列工作线程作为命令运行。php artisan queue:work

我知道它作为 PID1 运行。因此,当进程崩溃时,Kubernetes 将自动重新启动 pod。但是,当我们删除 pod 时,它需要一段时间(大约 20 秒(才能停止,并且它以退出代码137而不是0.当我exec进入豆荚时,我可以看到这一点。它在删除时返回terminated with exit code 137

在这篇文章中,我读到Laravel(我们正在使用7.x(是异步的,应该对SIGTERM信号做出反应。那么,当我们停止 Pod 时,kubernetes 正在发送 SIGTERM 信号,并且应该优雅地停止 pod,这难道不是合乎逻辑的吗?优雅地应该是退出代码0,对吧?

我希望任何人都可以解释我在这里做错了什么。

apiVersion: apps/v1
kind: Deployment
metadata:
namespace: hip-prod
name: worker
labels:
worker: worker
spec:
minReadySeconds: 5
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
worker: worker
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 50%
type: RollingUpdate
template:
metadata:
labels:
worker: worker
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: worker
image: my-laravel-image/app:latest
command: ["php", "artisan", "queue:work"]
imagePullPolicy: Always

你有没有尝试过用这个来构建你的docker镜像?

STOPSIGNAL SIGTERM

最新更新