我们正在 Kubernetes 上部署 Laravel 应用程序。只是应用程序不是问题,但队列工作人员是。我们从多个来源中了解到,建议将 queueworker 作为单独的 Deployment 运行。因此,在将队列工作器作为命令运行的 kubeconfig 部分下方。 php artisan queue:work
我知道它作为 PID1 运行。所以当进程崩溃时,Kubernetes 会自动重启 pod。然而,问题是,当我们删除 pod 时,它需要一段时间(大约 20 秒)才能停止,并且它以退出代码 137 而不是 0 退出。当我 exec 进入 pod 时,我可以看到这一点。它在删除时返回 terminated with exit code 137

this article 上,我读到 Laravel(我们使用的是 7.x)是异步的,应该对 SIGTERM 信号使用react。那么,当我们停止 pod 时,kubernetes 发送一个 SIGTERM 信号,并且应该优雅地停止 pod,这难道不合逻辑吗?优雅地应该是 exitcode 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-image 吗?

STOPSIGNAL SIGTERM

关于linux - 如何优雅地停止 Laravel Queueworker,作为 docker 镜像运行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62446226/

10-16 23:42