0

我们使用以下 deployment.yaml 设置了 Celery Beat:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: celery-beat
  labels:
    deployment: celery-beat
spec:
  replicas: 1
  minReadySeconds: 120
  selector:
    matchLabels:
      app: celery-beat
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 0 # Would rather have downtime than an additional instance in service?
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: celery-beat
    spec:
      containers:
        - name: celery-beat
          image: image_url
          command: ["/var/app/scripts/kube_worker_beat_start.sh"]
          imagePullPolicy: Always
          ports:
            - containerPort: 8000
              name: http-server
          livenessProbe: #From https://github.com/celery/celery/issues/4079#issuecomment-437415370
            exec:
              command:
                - /bin/sh
                - -c
                - celery -A app_name status | grep ".*OK"
            initialDelaySeconds: 3600 
            periodSeconds: 3600
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - celery -A app_name status | grep ".*OK"
            initialDelaySeconds: 60
            periodSeconds: 30 
          resources:
            limits:
              cpu: "0.5" #500mcores - only really required on install
            requests:
              cpu: "30m"

我发现RollingUpdate设置很棘手,因为使用 Celery Beat 你真的不想要两个实例,否则你可能会完成重复的任务。这对我们来说非常重要,因为我们使用它来发送推送通知。

使用当前设置,当部署推出时,会有 3-5 分钟的停机时间,因为现有实例会立即终止,我们必须等待新实例自行设置。

有没有更好的配置方法来减少停机时间,同时确保最多有一项服务在服务中?

4

0 回答 0