跳到内容

配置部署资源

config-deployment ConfigMap,称为部署 ConfigMap,包含确定如何配置支持 Knative 服务的 Kubernetes Deployment 资源的设置。此 ConfigMap 位于 knative-serving 命名空间中。

您可以通过运行以下命令查看当前的 config-deployment ConfigMap

kubectl get configmap -n knative-serving config-deployment -oyaml

示例 config-deployment ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-deployment
  namespace: knative-serving
  labels:
    serving.knative.dev/release: devel
  annotations:
    knative.dev/example-checksum: "fa67b403"
data:
  # This is the Go import path for the binary that is containerized
  # and substituted here.
  queue-sidecar-image: ko://knative.k8s.ac.cn/serving/cmd/queue
  # List of repositories for which tag to digest resolving should be skipped
  registries-skipping-tag-resolving: "kind.local,ko.local,dev.local"
  # digest-resolution-timeout is the maximum time allowed for an image's
  # digests to be resolved.
  digest-resolution-timeout: "10s"
  # progress-deadline is the duration we wait for the deployment to
  # be ready before considering it failed.
  progress-deadline: "600s"
  # queue-sidecar-cpu-request is the requests.cpu to set for the queue proxy sidecar container.
  # If omitted, a default value (currently "25m"), is used.
  queue-sidecar-cpu-request: "25m"
  # queue-sidecar-cpu-limit is the limits.cpu to set for the queue proxy sidecar container.
  # If omitted, no value is specified and the system default is used.
  queue-sidecar-cpu-limit: "1000m"
  # queue-sidecar-memory-request is the requests.memory to set for the queue proxy container.
  # If omitted, no value is specified and the system default is used.
  queue-sidecar-memory-request: "400Mi"
  # queue-sidecar-memory-limit is the limits.memory to set for the queue proxy container.
  # If omitted, no value is specified and the system default is used.
  queue-sidecar-memory-limit: "800Mi"
  # queue-sidecar-ephemeral-storage-request is the requests.ephemeral-storage to
  # set for the queue proxy sidecar container.
  # If omitted, no value is specified and the system default is used.
  queue-sidecar-ephemeral-storage-request: "512Mi"
  # queue-sidecar-ephemeral-storage-limit is the limits.ephemeral-storage to set
  # for the queue proxy sidecar container.
  # If omitted, no value is specified and the system default is used.
  queue-sidecar-ephemeral-storage-limit: "1024Mi"

配置进度截止时间

配置进度截止时间设置允许您指定在系统报告回 Knative 修订版部署进度失败之前等待部署进度的最大时间(以秒或分钟为单位)。

默认进度截止时间为 600 秒。此值表示为 Golang time.Duration 字符串表示形式,必须四舍五入到秒精度。

如果在由此设置定义的时间限制内无法实现初始扩展,则 Knative 自动缩放器组件会将修订版扩展到 0,并且 Knative 服务将进入终端 Failed 状态。

如果在您的 Knative 部署中出现以下任何问题,您可能希望将此设置配置为更高的值

  • 由于图像大小,拉取服务图像需要很长时间。
  • 由于初始化缓存状态,服务需要很长时间才能变为 READY
  • 集群依赖于集群自动缩放来为新 Pod 分配资源。

有关更多信息,请参阅 Kubernetes 文档

进度截止时间设置可以在全局级别通过 ConfigMap 配置,也可以在每个修订版级别使用注释配置。

  • 全局密钥: progress-deadline
  • 每个修订版注释密钥: serving.knative.dev/progress-deadline
  • 可能的值: time.Duration
  • 默认: "600s"

示例

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-deployment
  namespace: knative-serving
  labels:
    serving.knative.dev/release: devel
  annotations:
    knative.dev/example-checksum: "fa67b403"
data:
  progress-deadline: "10m"
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
spec:
  template:
    metadata:
      annotations:
        serving.knative.dev/progress-deadline: "60s" 
    spec:
      containers:
        - image: ghcr.io/knative/helloworld-go:latest

跳过标签解析

您可以通过修改 registries-skipping-tag-resolving ConfigMap 设置来配置 Knative Serving 以跳过部署的标签解析。

以下示例显示了如何为 registry.example.com 禁用标签解析

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-deployment
  namespace: knative-serving
  labels:
    serving.knative.dev/release: devel
  annotations:
    knative.dev/example-checksum: "fa67b403"
data:
  # List of repositories for which tag to digest resolving should be skipped
  registries-skipping-tag-resolving: registry.example.com

配置可选择的 RuntimeClassName

您可以通过修改 runtime-class-name 设置来配置 Knative Serving 以使用指定的 RuntimeClassName(Pod.Spec.RuntimeClassName)配置部署。

该设置与服务标签一起使用,并将配置默认设置或与大多数标签匹配的设置。

示例

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-deployment
  namespace: knative-serving
data:
  runtime-class-name: |
    kata: {}
    gvisor:
      selector:
        my-label: selector
apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
  name: knative-serving
  namespace: knative-serving
spec:
  config:
    deployment:
      runtime-class-name: |
        kata: {}
        gvisor:
          selector:
            my-label: selector

有关更多信息,请参阅 Kubernetes RuntimeClass 文档。

另外,有一个功能标志允许 手动配置 RuntimeClassName

我们使用分析和 Cookie 来了解网站流量。有关您使用我们网站的信息将与 Google 共享,用于该目的。了解更多。