×

启动探测验证服务是否已成功启动,有助于减少启动过程缓慢的容器的冷启动时间。启动探测仅在容器的初始化阶段运行,不会定期执行。如果启动探测失败,容器将遵守定义的restartPolicy

进度截止时间

默认情况下,服务具有进度截止时间,该时间定义了服务完成初始启动的时间限制。使用启动探测时,请确保进度截止时间设置为超过启动探测所需的最大时间。如果进度截止时间设置得太低,启动探测可能在截止时间到达之前无法完成,这可能会阻止服务启动。

如果您在部署中遇到以下任何情况,请考虑增加进度截止时间

  • 由于服务镜像大小,拉取镜像需要很长时间。

  • 由于初始缓存填充,服务需要很长时间才能变为READY状态。

  • 集群依赖于自动扩展来为新 Pod 分配资源。

配置启动探测

对于 OpenShift Serverless Serving,默认情况下未定义启动探测。您可以在部署配置中为容器定义启动探测。

步骤
  • 通过修改部署配置来为您的服务定义启动探测。以下示例显示了一个包含两个容器的配置

    已定义的启动探测示例
    apiVersion: serving.knative.dev/v1
    kind: Service
    # ...
    spec:
      template:
        spec:
           containers:
            - name: first-container
              image: <image>
              ports:
                - containerPort: 8080
              # ...
              startupProbe: (1)
              httpGet:
                port: 8080
                path: "/"
            - name: second-container
              image: <image>
              # ...
              startupProbe: (2)
              httpGet:
                port: 8081
                path: "/"
    1 first-container的启动探测。
    2 second-container的启动探测。

配置进度截止时间

您可以配置进度截止时间设置以指定在系统为 Knative Revision 报告失败之前允许部署进行的最大时间。此时间限制可以以秒或分钟为单位指定。

为了有效配置进度截止时间,请考虑以下参数

  • initialDelaySeconds

  • failureThreshold

  • periodSeconds

  • timeoutSeconds

如果在指定的时间限制内未达到初始规模,则 Knative Autoscaler 组件会将修订版规模缩放到0,并且 Knative 服务将进入终端Failed状态。

默认情况下,进度截止时间设置为 600 秒。此值指定为 Golang time.Duration 字符串,必须四舍五入到最接近的秒。

步骤
  • 要配置进度截止时间设置,请在部署配置中使用注释。

    将进度截止时间设置为 60 秒的示例
    apiVersion: serving.knative.dev/v1
    kind: Service
    ...
    spec:
      template:
        metadata:
           annotations:
                serving.knative.dev/progress-deadline: "60s"
        spec:
            containers:
                - image: ghcr.io/knative/helloworld-go:latest