如何在Kubernetes上最好地运行Symfony Messenger Worker

如何在Kubernetes上最好地运行Symfony Messenger Worker,symfony,deployment,kubernetes,symfony4,symfony-messenger,Symfony,Deployment,Kubernetes,Symfony4,Symfony Messenger,在Kubernetes上运行messenger:consume任务的最佳方式是什么 部署? 如果我们使用具有一定数量副本的部署,这可能会起作用,但是如果我们对部署进行滚动更新,然后导致替换pod,尽管它现在正在处理一条长时间运行的消息,该怎么办 为了防止出现这种情况,我们可能会设置一个较高的terminationGracePeriodSeconds,并结合使用lifecycle.preStop apiVersion: apps/v1 kind: Deployment metadata: cr

在Kubernetes上运行
messenger:consume
任务的最佳方式是什么

部署?

如果我们使用具有一定数量副本的部署,这可能会起作用,但是如果我们对部署进行滚动更新,然后导致替换pod,尽管它现在正在处理一条长时间运行的消息,该怎么办

为了防止出现这种情况,我们可能会设置一个较高的
terminationGracePeriodSeconds
,并结合使用
lifecycle.preStop

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: deploy
  name: deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      run: deploy
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: deploy
    spec:
      terminationGracePeriodSeconds: 6000
      containers:
      - command:
        - sh
        - -c
        - sleep 1d # bin/console messenger:consume
        image: bash
        name: deploy
        lifecycle:
          preStop:
            exec:
              command:
              - sh
              - -c
              - echo "Test if a message is consumed at the moment and prevent POD shutdown till then?"                    
但是在我的测试过程中,即使
lifecycle.preStop
任务提前停止,由
terminationGracePeriodSeconds
定义的完整时间仍然会等待,直到pod终止

有人有好主意吗?

这对我很有用:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: agent
spec:
  replicas: 8
  selector:
    matchLabels:
      id: agent-pod
  template:
    metadata:
      labels:
        id: agent-pod
    spec:
      terminationGracePeriodSeconds: 3600
      containers:
      - name: agent
        volumeMounts:
          - mountPath: /share
            name: share
        lifecycle:
          preStop:
            exec:
              command: ["sh", "-c", "touch /tmp/kill_me"]
        command:
        - /bin/sh
        - -c
        - >
          sleep 3 && rm -rf var/cache/* && bin/console cache:clear &&
          while ! [ -f /tmp/kill_me ];
            do
            bin/console messenger:consume queue --limit=1 --time-limit=60 -vv
          done;
        image: my-symfony-agent-image

更多。

此组件是实验性的。
所以请三思!实验性和热点:D但这也可能被视为部署中任何其他长时间运行的进程的Kubernetes问题。它似乎按照预期工作。请参阅及。我建议使用另一种方法,如蓝绿部署。